I am fairly familiar with Redis having used it in an earlier project in java.  This time I started to use it in Python given that I was completely sold on its simplicity and performance.  Having spent quite some time I decided to just jump in with a pip install redis.
To create a redis object you use the following code
and then you use the variable r to execute all standard redis commands. Very simple and clear and having seen a few sample code snippets I was all set or so I thought. The confusion was that I thought that redis.Redis() represented the connection handle and so I could execute various commands against it. So to free the connection I looked at the ConnectionPool class and it had a very helpful release() method. So at the end of my method, I simply did a
So morale of the story is that each client library to a framework can be very different. Dont assume that the framework dictates the library interface. It can provide more layers of abstraction on top.
To create a redis object you use the following code
import redis
mypool = redis.ConnectionPool(connection_class=UnixDomainSocketConnection,                                   path = '/var/redis/redis.sock')
r=redis.Redis(connection_pool = mypool)
 
and then you use the variable r to execute all standard redis commands. Very simple and clear and having seen a few sample code snippets I was all set or so I thought. The confusion was that I thought that redis.Redis() represented the connection handle and so I could execute various commands against it. So to free the connection I looked at the ConnectionPool class and it had a very helpful release() method. So at the end of my method, I simply did a
mypool.release(r)
So morale of the story is that each client library to a framework can be very different. Dont assume that the framework dictates the library interface. It can provide more layers of abstraction on top.
 
No comments:
Post a Comment