You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was asked to post the discussion here from here.
I have a class written to interact with my Redis DB. In it, I thought about using a method for session handling (as I would do with other DBs) (exception handling is handled elsewhere):
Imagine that I perform a with istruction to open the Pipeline, running one or more commands and executing them. e.g.:
with self._make_session() as session:
return method(self, session, *args, **kwargs)
I noticed that the code above only works the first time in my backend, the latters raise a NoneType error. So I looked into the Pipeline code and found out that close calls the reset method that has this part at the end:
if self.connection:
self.connection_pool.release(self.connection)
self.connection = None
Was this done for some reason in particular? It seems like that since the connection closes, from the second time I create a session it simply points to None. I had to quickly fix it like this:
Hi @Frank995,
Could you please share more details about how your client is initialized? Are you using a synchronous or asynchronous client?
Additionally, please provide more information on what can be included in this method(self, session, *args, **kwargs).
Typically, when creating a pipeline object, the same instance is used to add all the commands that should be executed together. The actual communication with the server occurs when pipe.execute() is called. At this point, a connection is retrieved from the connection pool and assigned to the self.connection field for communication. At the end of the method, the reset method is executed, returning self.connection to the pool and resetting both the connection and the pipeline object's state.
If your code adds commands to the pipeline but does not call execute() before reset() is invoked, the accumulated list of commands will be lost, preventing execution.
I was asked to post the discussion here from here.
I have a class written to interact with my Redis DB. In it, I thought about using a method for session handling (as I would do with other DBs) (exception handling is handled elsewhere):
Imagine that I perform a with istruction to open the Pipeline, running one or more commands and executing them. e.g.:
I noticed that the code above only works the first time in my backend, the latters raise a NoneType error. So I looked into the Pipeline code and found out that close calls the reset method that has this part at the end:
Was this done for some reason in particular? It seems like that since the connection closes, from the second time I create a session it simply points to None. I had to quickly fix it like this:
Do you have any ideas of why?
The text was updated successfully, but these errors were encountered: