5.7.17. vlcp.utils.redisclient¶
Note
This document is generated from the source file.
Created on 2016/1/8
author: | hubo |
---|
-
class
vlcp.utils.redisclient.
RedisClient
(url=None, db=None, protocol=None)¶ -
__init__
(url=None, db=None, protocol=None)¶ Redis client to communicate with Redis server. Several connections are created for different functions.
Parameters: - url – connectiom url, e.g. ‘tcp://localhost/’. If not specified, redisclient.url in configuration is used
- db – default database. If not specified, redisclient.db in configuration is used, which defaults to 0.
- protocol – use a pre-created protocol instance instead of creating a new instance
-
execute_command
(container, *args)¶ - Execute command on Redis server:
- For (P)SUBSCRIBE/(P)UNSUBSCRIBE, the command is sent to the subscribe connection. It is recommended to use (p)subscribe/(p)unsubscribe method instead of directly call the command
- For BLPOP, BRPOP, BRPOPLPUSH, the command is sent to a separated connection. The connection is recycled after command returns.
- For other commands, the command is sent to the default connection.
-
get_connection
(container)¶ Get an exclusive connection, useful for blocked commands and transactions.
You must call release or shutdown (not recommanded) to return the connection after use.
Parameters: container – routine container Returns: RedisClientBase object, with some commands same as RedisClient like execute_command, batch_execute, register_script etc.
-
make_connobj
(container)¶ Return an object to be used like a connection. Put the connection-like object in module.connections to make RedisClient shutdown on module unloading.
-
psubscribe
(container, *keys)¶ Subscribe to specified globs :param container: routine container :param *keys: subscribed globs :returns: list of event matchers for the specified globs
-
punsubscribe
(container, *keys)¶ Unsubscribe specified globs. Every subscribed glob should be unsubscribed exactly once, even if duplicated subscribed.
Parameters: - container – routine container
- *keys –
subscribed globs
-
shutdown
(container)¶ Shutdown all connections. Exclusive connections created by get_connection will shutdown after release()
-
subscribe
(container, *keys)¶ Subscribe to specified channels :param container: routine container :param *keys: subscribed channels :returns: list of event matchers for the specified channels
-
subscribe_state_matcher
(container, connected=True)¶ Return a matcher to match the subscribe connection status.
Parameters: - container – a routine container. NOTICE: this method is not a routine.
- connected – if True, the matcher matches connection up. If False, the matcher matches connection down.
Returns: an event matcher.
-
-
class
vlcp.utils.redisclient.
RedisClientBase
(conn=None, parent=None, protocol=None)¶ Connect to Redis server
-
__init__
(conn=None, parent=None, protocol=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
context
(container, release=True, lockconn=True)¶ Use with statement to manage the connection
Params release: if True(default), release the connection when leaving with scope Params lockconn: if True(default), do not allow reconnect during with scope; execute commands on a disconnected connection raises Exceptions.
-
ensure_registerd
(container, *scripts)¶ Ensure that these scripts are cached on the server. Important when using scripts with batch_execute. :param container: routine container. :param *scripts: registered script tuples, return value of register_script
-
eval_registered
(container, registerd_script, *args)¶ eval a registered script. If the script is not cached on the server, it is automatically cached.
-
register_script
(container, script)¶ register a script to this connection.
Returns: registered script. This is a tuple (sha1, script). Pass the tuple to eval_registered, ensure_registerd as registerd_script parameter.
-
release
(container)¶ Release the connection, leave it to be reused later.
-
shutdown
(container)¶ Shutdown all connections to Redis server
-
-
exception
vlcp.utils.redisclient.
RedisConnectionDown
¶
-
exception
vlcp.utils.redisclient.
RedisConnectionRestarted
¶