PubSubClient API¶
-
class
tornadis.
PubSubClient
(autoconnect=True, password=None, db=0, **connection_kwargs)¶ Bases:
tornadis.client.Client
High level specific object to interact with pubsub redis.
The call() method is forbidden with this object.
More informations on the redis side: http://redis.io/topics/pubsub
-
__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)¶ Not allowed method with PubSubClient object.
-
call
(*args, **kwargs)¶ Not allowed method with PubSubClient object.
-
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.
-
pubsub_pop_message
(*args, **kwargs)¶ Pops a message for a subscribed client.
Parameters: deadline (int) – max number of seconds to wait (None => no timeout) Returns: - Future with the popped message as result (or None if timeout
- or ConnectionError object in case of connection errors or ClientError object if you are not subscribed)
-
pubsub_psubscribe
(*args)¶ Subscribes to a list of patterns.
Parameters: *args – variable list of patterns to subscribe. Returns: Future with True as result if the subscribe is ok. Return type: Future Examples
>>> yield client.pubsub_psubscribe("channel*", "foo*")
-
pubsub_punsubscribe
(*args)¶ Unsubscribes from a list of patterns.
Parameters: *args – variable list of patterns to unsubscribe. Returns: Future with True as result if the unsubscribe is ok. Return type: Future Examples
>>> yield client.pubsub_punsubscribe("channel*", "foo*")
-
pubsub_subscribe
(*args)¶ Subscribes to a list of channels.
Parameters: *args – variable list of channels to subscribe. Returns: Future with True as result if the subscribe is ok. Return type: Future Examples
>>> yield client.pubsub_subscribe("channel1", "channel2")
-
pubsub_unsubscribe
(*args)¶ Unsubscribes from a list of channels.
Parameters: *args – variable list of channels to unsubscribe. Returns: Future with True as result if the unsubscribe is ok. Return type: Future Examples
>>> yield client.pubsub_unsubscribe("channel1", "channel2")
-