diff options
author | Konstantin Merenkov <kmerenkov@gmail.com> | 2010-04-12 15:07:31 +0800 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2010-04-12 15:54:21 +0800 |
commit | 4dec96f235d3d1ef9fd1eb8a1549b75caae36c59 (patch) | |
tree | ec81f231b43d4d116e1f4fc87f10c15e772d95e8 /redis/client.py | |
parent | 4efa5de487363b7c1d86b0a6a6719dee7fe507b4 (diff) | |
download | redis-py-4dec96f235d3d1ef9fd1eb8a1549b75caae36c59.tar.gz |
[issue 29] Redis instance doesn't use shared connection pool by default
* Redis constructor accepts connection_pool keyword argument,
that defaults to None (no shared connection pool).
However, you can create ConnectionManager instance yourself
and pass it to as many Redis instances as you want, making
them use shared connection pool.
* Renamed ConnectionManager to ConnectionPool.
* Exported ConnectionPool, so now you can import it in your code
and create instances.
* Removed test_pipeline_with_fresh_connection test, since
all redis instances don't use shared pool by default now.
* corrected few typos in comments.
* repaired the rest of tests.
Diffstat (limited to 'redis/client.py')
-rw-r--r-- | redis/client.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/redis/client.py b/redis/client.py index 7dc5e06..09a21fb 100644 --- a/redis/client.py +++ b/redis/client.py @@ -8,7 +8,7 @@ from redis.exceptions import ConnectionError, ResponseError, InvalidResponse from redis.exceptions import RedisError, AuthenticationError -class ConnectionManager(threading.local): +class ConnectionPool(threading.local): "Manages a list of connections on the local thread" def __init__(self): self.connections = {} @@ -30,9 +30,6 @@ class ConnectionManager(threading.local): return self.connections.values() -connection_manager = ConnectionManager() - - class Connection(object): "Manages TCP communication to and from a Redis server" def __init__(self, host='localhost', port=6379, db=0, password=None, @@ -236,11 +233,13 @@ class Redis(threading.local): def __init__(self, host='localhost', port=6379, db=0, password=None, socket_timeout=None, + connection_pool=None, charset='utf-8', errors='strict'): self.encoding = charset self.errors = errors self.connection = None self.subscribed = False + self.connection_pool = connection_pool and connection_pool or ConnectionPool() self.select(db, host, port, password, socket_timeout) #### Legacty accessors of connection information #### @@ -376,7 +375,7 @@ class Redis(threading.local): #### CONNECTION HANDLING #### def get_connection(self, host, port, db, password, socket_timeout): "Returns a connection object" - conn = connection_manager.get_connection( + conn = self.connection_pool.get_connection( host, port, db, password, socket_timeout) # if for whatever reason the connection gets a bad password, make # sure a subsequent attempt with the right password makes its way |