ClientPool(max_size=-1, client_timeout=-1, autoclose=False, **client_kwargs)¶
High level object to deal with a pool of redis clients.
__init__(max_size=-1, client_timeout=-1, autoclose=False, **client_kwargs)¶
- max_size (int) – max size of the pool (-1 means “no limit”).
- client_timeout (int) – timeout in seconds of a connection released to the pool (-1 means “no timeout”).
- autoclose (boolean) – automatically disconnect released connections with lifetime > client_timeout (test made every client_timeout/10 seconds).
- client_kwargs (dict) – Client constructor arguments.
Returns a ContextManagerFuture to be yielded in a with statement.
Returns: A ContextManagerFuture object.
>>> with (yield pool.connected_client()) as client: # client is a connected tornadis.Client instance # it will be automatically released to the pool thanks to # the "with" keyword reply = yield client.call("PING")
Disconnects all pooled client objects.
Gets a Client object (not necessary connected).
If max_size is reached, this method will return None (and won’t block).
Returns: A Client instance (not necessary connected) as result (or None).
Gets a connected Client object.
If max_size is reached, this method will block until a new client object is available.
- A Future object with connected Client instance as a result
- (or ClientError if there was a connection problem)
(pre)Connects some or all redis clients inside the pool.
Parameters: size (int) – number of redis clients to build and to connect (-1 means all clients if pool max_size > -1) Raises:
ClientError– when size == -1 and pool max_size == -1
Releases a client object to the pool.
Parameters: client – Client object.