Client API¶
-
class
tornadis.
Client
(autoconnect=True, password=None, db=0, **connection_kwargs)¶ Bases:
object
High level object to interact with redis.
Variables: - autoconnect (boolean) – True if the client is in autoconnect mode (and in autoreconnection mode) (default True).
- password (string) – the password to authenticate with.
- db (int) – database number.
- connection_kwargs (dict) –
Connection
object kwargs (note that read_callback and close_callback args are set automatically).
-
__init__
(autoconnect=True, password=None, db=0, **connection_kwargs)¶ Constructor.
Parameters: - autoconnect (boolean) – True if the client is in autoconnect mode (and in autoreconnection mode) (default True).
- password (string) – the password to authenticate with.
- db (int) – database number.
- **connection_kwargs –
Connection
object kwargs.
-
async_call
(*args, **kwargs)¶ Calls a redis command, waits for the reply and call a callback.
Following options are available (not part of the redis command itself):
- callback
- Function called (with the result as argument) when the result is available. If not set, the reply is silently discarded. In case of errors, the callback is called with a TornadisException object as argument.
Parameters: - *args – full redis command as variable length argument list or a Pipeline object (as a single argument).
- **kwargs – options as keyword parameters.
Examples
>>> def cb(result): pass >>> client.async_call("HSET", "key", "field", "val", callback=cb)
-
call
(*args, **kwargs)¶ Calls a redis command and returns a Future of the reply.
Parameters: - *args – full redis command as variable length argument list or a Pipeline object (as a single argument).
- **kwargs – internal private options (do not use).
Returns: - a Future with the decoded redis reply as result (when available) or
a ConnectionError object in case of connection error.
Raises: ClientError
– your Pipeline object is empty.Examples
>>> @tornado.gen.coroutine def foobar(): client = Client() result = yield client.call("HSET", "key", "field", "val")
-
connect
(*args, **kwargs)¶ Connects the client object to redis.
It’s safe to use this method even if you are already connected. Note: this method is useless with autoconnect mode (default).
Returns: a Future object with True as result if the connection was ok.
-
disconnect
()¶ Disconnects the client object from redis.
It’s safe to use this method even if you are already disconnected.
-
is_connected
()¶ Returns True is the client is connected to redis.
Returns: True if the client if connected to redis.