redtrio.lowlevel.client¶
The client module handles the Redis Client interface.
- Classes:
RedisClient
Module Contents¶
Classes¶
RedisClient communicates with the Redis server via its call method. |
-
redtrio.lowlevel.client.PUSH_COMMANDS¶
-
class
redtrio.lowlevel.client.RedisClient(host: str = '127.0.0.1', port: int = 6379, *, connection_pool=None, Reader: type = protocol.Resp3Reader, write_command: t.Callable = protocol.write_command)¶ RedisClient communicates with the Redis server via its call method.
-
host¶ The address to connect to (default: “127.0.0.1”).
- Type
str
-
port¶ The port to connect to (default: 6379).
- Type
int
-
connection_pool¶ The pool to use for connections. Leave as None to use the default ConnectionPool.
- Type
instance of a connection pool
-
Reader¶ The class to use for interpreting responses from Redis.
- Type
protocol class
-
write_command¶ The function to use to format commands to send to Redis.
- Type
function
-
async
receive(self, connection, push_only: bool = False)¶ Read the connection and return an object, calling any push callbacks.
It is not recommended to call this directly. Use the
call()method, instead.- Parameters
connection (trio.abc.Stream) – The connection to read from.
push_only (bool) – If a push is received, return None and don’t try to read anything else (default: False).
- Returns
- The response from Redis, as parsed by the Reader class (or None, if
push_only is True and a push is received).
-
async
send_command(self, command: bytes, *args: bytes, connection=None)¶ Send the given command to Redis and return the connection used.
It is not recommended to call this directly. Use the
call()method, instead.- Parameters
command (bytes) – The command to send, such as b”PING” or b”SET”.
*args (bytes) – The args to send with the command.
connection (trio.abc.Stream) – the connection to use, or None to get a connection from the pool.
- Returns
The connection used to send the command.
-
async
call(self, command: bytes, *args: bytes)¶ Send the given command to Redis and return the response.
- Parameters
command (bytes) – The command to send, such as b”PING” or b”SET”.
*args (bytes) – The args to send with the command.
- Returns
The response from Redis, as parsed by the Reader class.
Example
call(b”SET”, b”key_name”, b”value”) -> b”OK”
-
register_push_callback(self, push_type: bytes, callback: t.Callable)¶ Register a function to be called when a push is received.
-