Pool API¶
-
class
tornadis.
ClientPool
(max_size=-1, client_timeout=-1, autoclose=False, **client_kwargs)¶ Bases:
object
High level object to deal with a pool of redis clients.
-
__init__
(max_size=-1, client_timeout=-1, autoclose=False, **client_kwargs)¶ Constructor.
Parameters: - 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.
-
connected_client
()¶ Returns a ContextManagerFuture to be yielded in a with statement.
Returns: A ContextManagerFuture object. Examples
>>> 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")
-
destroy
()¶ Disconnects all pooled client objects.
-
get_client_nowait
()¶ 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).
-
get_connected_client
(*args, **kwargs)¶ Gets a connected Client object.
If max_size is reached, this method will block until a new client object is available.
Returns: - A Future object with connected Client instance as a result
- (or ClientError if there was a connection problem)
-
preconnect
(*args, **kwargs)¶ (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
-
release_client
(client)¶ Releases a client object to the pool.
Parameters: client – Client object.
-