Connections & Connection Pooling¶
Connection Pools¶
coredis
- class ConnectionPool(*, connection_class: Type[Connection] | None = None, max_connections: int | None = None, max_idle_time: int = 0, idle_check_interval: int = 1, **connection_kwargs: Any | None)[source]¶
Generic connection pool
Creates a connection pool. If
max_connections
is set, then this object raisesConnectionError
when the pool’s limit is reached.By default, TCP connections are created
connection_class
is specified. UseUnixDomainSocketConnection
for unix sockets.Any additional keyword arguments are passed to the constructor of connection_class.
- URL_QUERY_ARGUMENT_PARSERS: ClassVar[dict[str, Callable[[...], int | float | bool | str | None]]] = {'client_name': <class 'str'>, 'connect_timeout': <class 'float'>, 'idle_check_interval': <class 'int'>, 'max_connections': <class 'int'>, 'max_idle_time': <class 'int'>, 'noevict': <class 'bool'>, 'noreply': <class 'bool'>, 'notouch': <class 'bool'>, 'protocol_version': <class 'int'>, 'stream_timeout': <class 'float'>}¶
Mapping of querystring arguments to their parser functions
- classmethod from_url(url: str, db: int | None = None, decode_components: bool = False, **kwargs: Any) _CPT [source]¶
Returns a connection pool configured from the given URL.
For example:
redis://[:password]@localhost:6379/0
rediss://[:password]@localhost:6379/0
unix://[:password]@/path/to/socket.sock?db=0
Three URL schemes are supported:
redis:// creates a normal TCP socket connection
rediss:// creates a SSL wrapped TCP socket connection
unix://
creates a Unix Domain Socket connection
There are several ways to specify a database number. The parse function will return the first specified option:
A
db
querystring option, e.g.redis://localhost?db=0
If using the
redis://
scheme, the path argument of the url, e.g.redis://localhost/0
The
db
argument to this function.
If none of these options are specified,
db=0
is used.The
decode_components
argument allows this function to work with percent-encoded URLs. If this argument is set toTrue
all%xx
escapes will be replaced by their single-character equivalents after the URL has been parsed. This only applies to thehostname
,path
, andpassword
components. SeeURL_QUERY_ARGUMENT_PARSERS
for a comprehensive mapping of querystring parameters to how they are parsed.Any additional querystring arguments and keyword arguments will be passed along to the class constructor. The querystring arguments
connect_timeout
andstream_timeout
if supplied are parsed as float values.Note
In the case of conflicting arguments, querystring arguments always win.
- async get_connection(command_name: bytes | None = None, *args: ValueT, acquire: bool = True, **kwargs: ValueT | None) Connection [source]¶
Gets a connection from the pool
- release(connection: Connection) None [source]¶
Releases the
connection
back to the pool
- class BlockingConnectionPool(connection_class: Type[Connection] | None = None, queue_class: Type[Queue[Connection | None]] = asyncio.LifoQueue, max_connections: int | None = None, timeout: int = 20, max_idle_time: int = 0, idle_check_interval: int = 1, **connection_kwargs: ValueT | None)[source]¶
Bases:
ConnectionPool
Blocking connection pool:
>>> from coredis import Redis >>> client = Redis(connection_pool=BlockingConnectionPool())
It performs the same function as the default
ConnectionPool
, in that, it maintains a pool of reusable connections that can be shared by multiple redis clients.The difference is that, in the event that a client tries to get a connection from the pool when all of the connections are in use, rather than raising a
ConnectionError
(as the defaultConnectionPool
implementation does), it makes the client blocks for a specified number of seconds until a connection becomes available.Use
max_connections
to increase / decrease the pool size:>>> pool = BlockingConnectionPool(max_connections=10)
Use
timeout
to tell it either how many seconds to wait for a connection to become available, or to block forever:>>> # Block forever. >>> pool = BlockingConnectionPool(timeout=None) >>> # Raise a ``ConnectionError`` after five seconds if a connection is >>> # not available. >>> pool = BlockingConnectionPool(timeout=5)
Creates a connection pool. If
max_connections
is set, then this object raisesConnectionError
when the pool’s limit is reached.By default, TCP connections are created
connection_class
is specified. UseUnixDomainSocketConnection
for unix sockets.Any additional keyword arguments are passed to the constructor of connection_class.
- async get_connection(command_name: bytes | None = None, *args: ValueT, acquire: bool = True, **kwargs: ValueT | None) Connection [source]¶
Gets a connection from the pool
- release(connection: Connection) None [source]¶
Releases the connection back to the pool
- URL_QUERY_ARGUMENT_PARSERS: ClassVar[dict[str, Callable[[...], int | float | bool | str | None]]] = {'client_name': <class 'str'>, 'connect_timeout': <class 'float'>, 'idle_check_interval': <class 'int'>, 'max_connections': <class 'int'>, 'max_idle_time': <class 'int'>, 'noevict': <class 'bool'>, 'noreply': <class 'bool'>, 'notouch': <class 'bool'>, 'protocol_version': <class 'int'>, 'stream_timeout': <class 'float'>}¶
Mapping of querystring arguments to their parser functions
- classmethod from_url(url: str, db: int | None = None, decode_components: bool = False, **kwargs: Any) _CPT ¶
Returns a connection pool configured from the given URL.
For example:
redis://[:password]@localhost:6379/0
rediss://[:password]@localhost:6379/0
unix://[:password]@/path/to/socket.sock?db=0
Three URL schemes are supported:
redis:// creates a normal TCP socket connection
rediss:// creates a SSL wrapped TCP socket connection
unix://
creates a Unix Domain Socket connection
There are several ways to specify a database number. The parse function will return the first specified option:
A
db
querystring option, e.g.redis://localhost?db=0
If using the
redis://
scheme, the path argument of the url, e.g.redis://localhost/0
The
db
argument to this function.
If none of these options are specified,
db=0
is used.The
decode_components
argument allows this function to work with percent-encoded URLs. If this argument is set toTrue
all%xx
escapes will be replaced by their single-character equivalents after the URL has been parsed. This only applies to thehostname
,path
, andpassword
components. SeeURL_QUERY_ARGUMENT_PARSERS
for a comprehensive mapping of querystring parameters to how they are parsed.Any additional querystring arguments and keyword arguments will be passed along to the class constructor. The querystring arguments
connect_timeout
andstream_timeout
if supplied are parsed as float values.Note
In the case of conflicting arguments, querystring arguments always win.
- class ClusterConnectionPool(startup_nodes: Iterable[Node] | None = None, connection_class: Type[ClusterConnection] = ClusterConnection, queue_class: Type[Queue[Connection | None]] = asyncio.LifoQueue, max_connections: int | None = None, max_connections_per_node: bool = False, reinitialize_steps: int | None = None, skip_full_coverage_check: bool = False, nodemanager_follow_cluster: bool = True, readonly: bool = False, read_from_replicas: bool = False, max_idle_time: int = 0, idle_check_interval: int = 1, blocking: bool = False, timeout: int = 20, **connection_kwargs: Any | None)[source]¶
Bases:
ConnectionPool
Custom connection pool for
RedisCluster
client- Changes
Changed in version 4.4.0.
nodemanager_follow_cluster
now defaults toTrue
Deprecated since version 4.4.0.
readonly
renamed toread_from_replicas
- Parameters:
max_connections¶ – Maximum number of connections to allow concurrently from this client. If the value is
None
it will default to 32.max_connections_per_node¶ – Whether to use the value of
max_connections
on a per node basis or cluster wide. IfFalse
andblocking
isTrue
the per-node connection pools will have a maximum size ofmax_connections
divided by the number of nodes in the cluster.blocking¶ – If
True
the client will block at mosttimeout
seconds ifmax_connections
is reachd when trying to obtain a connectiontimeout¶ – Number of seconds to block if
block
isTrue
when trying to obtain a connection.skip_full_coverage_check¶ – Skips the check of cluster-require-full-coverage config, useful for clusters without the CONFIG command (For example with AWS Elasticache)
nodemanager_follow_cluster¶ – The node manager will during initialization try the last set of nodes that it was operating on. This will allow the client to drift along side the cluster if the cluster nodes move around alot.
read_from_replicas¶ – If
True
the client will route readonly commands to replicas
- URL_QUERY_ARGUMENT_PARSERS: ClassVar[dict[str, Callable[[...], int | float | bool | str | None]]] = {'blocking': <class 'bool'>, 'client_name': <class 'str'>, 'connect_timeout': <class 'float'>, 'idle_check_interval': <class 'int'>, 'max_connections': <class 'int'>, 'max_connections_per_node': <class 'bool'>, 'max_idle_time': <class 'int'>, 'noevict': <class 'bool'>, 'noreply': <class 'bool'>, 'notouch': <class 'bool'>, 'protocol_version': <class 'int'>, 'read_from_replicas': <class 'bool'>, 'reinitialize_steps': <class 'int'>, 'skip_full_coverage_check': <class 'bool'>, 'stream_timeout': <class 'float'>}¶
Mapping of querystring arguments to their parser functions
- async get_connection(command_name: bytes | None = None, *keys: ValueT, acquire: bool = True, **options: ValueT | None) Connection [source]¶
Gets a connection from the pool
- release(connection: Connection) None [source]¶
Releases the connection back to the pool
- async get_random_connection(primary: bool = False) ClusterConnection [source]¶
Opens new connection to random redis server in the cluster
- async get_connection_by_slot(slot: int) ClusterConnection [source]¶
Determines what server a specific slot belongs to and return a redis object that is connected
- async get_connection_by_node(node: ManagedNode) ClusterConnection [source]¶
Gets a connection by node
- classmethod from_url(url: str, db: int | None = None, decode_components: bool = False, **kwargs: Any) _CPT ¶
Returns a connection pool configured from the given URL.
For example:
redis://[:password]@localhost:6379/0
rediss://[:password]@localhost:6379/0
unix://[:password]@/path/to/socket.sock?db=0
Three URL schemes are supported:
redis:// creates a normal TCP socket connection
rediss:// creates a SSL wrapped TCP socket connection
unix://
creates a Unix Domain Socket connection
There are several ways to specify a database number. The parse function will return the first specified option:
A
db
querystring option, e.g.redis://localhost?db=0
If using the
redis://
scheme, the path argument of the url, e.g.redis://localhost/0
The
db
argument to this function.
If none of these options are specified,
db=0
is used.The
decode_components
argument allows this function to work with percent-encoded URLs. If this argument is set toTrue
all%xx
escapes will be replaced by their single-character equivalents after the URL has been parsed. This only applies to thehostname
,path
, andpassword
components. SeeURL_QUERY_ARGUMENT_PARSERS
for a comprehensive mapping of querystring parameters to how they are parsed.Any additional querystring arguments and keyword arguments will be passed along to the class constructor. The querystring arguments
connect_timeout
andstream_timeout
if supplied are parsed as float values.Note
In the case of conflicting arguments, querystring arguments always win.
- class BlockingClusterConnectionPool(startup_nodes: Iterable[Node] | None = None, connection_class: Type[ClusterConnection] = ClusterConnection, queue_class: Type[Queue[Connection | None]] = asyncio.LifoQueue, max_connections: int | None = None, max_connections_per_node: bool = False, reinitialize_steps: int | None = None, skip_full_coverage_check: bool = False, nodemanager_follow_cluster: bool = True, readonly: bool = False, read_from_replicas: bool = False, max_idle_time: int = 0, idle_check_interval: int = 1, timeout: int = 20, **connection_kwargs: Any | None)[source]¶
Bases:
ClusterConnectionPool
Added in version 4.3.0.
Blocking connection pool for
RedisCluster
clientNote
This is just a convenience subclass of
ClusterConnectionPool
that setsblocking
toTrue
- Changes
Changed in version 4.4.0.
nodemanager_follow_cluster
now defaults toTrue
Deprecated since version 4.4.0.
readonly
renamed toread_from_replicas
- Parameters:
max_connections¶ – Maximum number of connections to allow concurrently from this client.
max_connections_per_node¶ – Whether to use the value of
max_connections
on a per node basis or cluster wide. IfFalse
the per-node connection pools will have a maximum size ofmax_connections
divided by the number of nodes in the cluster.timeout¶ – Number of seconds to block when trying to obtain a connection.
skip_full_coverage_check¶ – Skips the check of cluster-require-full-coverage config, useful for clusters without the CONFIG command (like aws)
nodemanager_follow_cluster¶ – The node manager will during initialization try the last set of nodes that it was operating on. This will allow the client to drift along side the cluster if the cluster nodes move around alot.
- URL_QUERY_ARGUMENT_PARSERS: ClassVar[dict[str, Callable[[...], int | float | bool | str | None]]] = {'blocking': <class 'bool'>, 'client_name': <class 'str'>, 'connect_timeout': <class 'float'>, 'idle_check_interval': <class 'int'>, 'max_connections': <class 'int'>, 'max_connections_per_node': <class 'bool'>, 'max_idle_time': <class 'int'>, 'noevict': <class 'bool'>, 'noreply': <class 'bool'>, 'notouch': <class 'bool'>, 'protocol_version': <class 'int'>, 'read_from_replicas': <class 'bool'>, 'reinitialize_steps': <class 'int'>, 'skip_full_coverage_check': <class 'bool'>, 'stream_timeout': <class 'float'>}¶
Mapping of querystring arguments to their parser functions
- classmethod from_url(url: str, db: int | None = None, decode_components: bool = False, **kwargs: Any) _CPT ¶
Returns a connection pool configured from the given URL.
For example:
redis://[:password]@localhost:6379/0
rediss://[:password]@localhost:6379/0
unix://[:password]@/path/to/socket.sock?db=0
Three URL schemes are supported:
redis:// creates a normal TCP socket connection
rediss:// creates a SSL wrapped TCP socket connection
unix://
creates a Unix Domain Socket connection
There are several ways to specify a database number. The parse function will return the first specified option:
A
db
querystring option, e.g.redis://localhost?db=0
If using the
redis://
scheme, the path argument of the url, e.g.redis://localhost/0
The
db
argument to this function.
If none of these options are specified,
db=0
is used.The
decode_components
argument allows this function to work with percent-encoded URLs. If this argument is set toTrue
all%xx
escapes will be replaced by their single-character equivalents after the URL has been parsed. This only applies to thehostname
,path
, andpassword
components. SeeURL_QUERY_ARGUMENT_PARSERS
for a comprehensive mapping of querystring parameters to how they are parsed.Any additional querystring arguments and keyword arguments will be passed along to the class constructor. The querystring arguments
connect_timeout
andstream_timeout
if supplied are parsed as float values.Note
In the case of conflicting arguments, querystring arguments always win.
- async get_connection(command_name: bytes | None = None, *keys: ValueT, acquire: bool = True, **options: ValueT | None) Connection ¶
Gets a connection from the pool
- async get_connection_by_node(node: ManagedNode) ClusterConnection ¶
Gets a connection by node
- async get_connection_by_slot(slot: int) ClusterConnection ¶
Determines what server a specific slot belongs to and return a redis object that is connected
- async get_random_connection(primary: bool = False) ClusterConnection ¶
Opens new connection to random redis server in the cluster
- release(connection: Connection) None ¶
Releases the connection back to the pool
- class SentinelConnectionPool(service_name: StringT, sentinel_manager: Sentinel[Any], is_primary: bool = True, check_connection: bool = True, **kwargs: Any)[source]¶
Bases:
ConnectionPool
Sentinel backed connection pool.
Creates a connection pool. If
max_connections
is set, then this object raisesConnectionError
when the pool’s limit is reached.By default, TCP connections are created
connection_class
is specified. UseUnixDomainSocketConnection
for unix sockets.Any additional keyword arguments are passed to the constructor of connection_class.
- URL_QUERY_ARGUMENT_PARSERS: ClassVar[Dict[str, Callable[..., int | float | bool | str | None]]] = {'client_name': <class 'str'>, 'connect_timeout': <class 'float'>, 'idle_check_interval': <class 'int'>, 'max_connections': <class 'int'>, 'max_idle_time': <class 'int'>, 'noevict': <class 'bool'>, 'noreply': <class 'bool'>, 'notouch': <class 'bool'>, 'protocol_version': <class 'int'>, 'stream_timeout': <class 'float'>}¶
Mapping of querystring arguments to their parser functions
- classmethod from_url(url: str, db: int | None = None, decode_components: bool = False, **kwargs: Any) _CPT ¶
Returns a connection pool configured from the given URL.
For example:
redis://[:password]@localhost:6379/0
rediss://[:password]@localhost:6379/0
unix://[:password]@/path/to/socket.sock?db=0
Three URL schemes are supported:
redis:// creates a normal TCP socket connection
rediss:// creates a SSL wrapped TCP socket connection
unix://
creates a Unix Domain Socket connection
There are several ways to specify a database number. The parse function will return the first specified option:
A
db
querystring option, e.g.redis://localhost?db=0
If using the
redis://
scheme, the path argument of the url, e.g.redis://localhost/0
The
db
argument to this function.
If none of these options are specified,
db=0
is used.The
decode_components
argument allows this function to work with percent-encoded URLs. If this argument is set toTrue
all%xx
escapes will be replaced by their single-character equivalents after the URL has been parsed. This only applies to thehostname
,path
, andpassword
components. SeeURL_QUERY_ARGUMENT_PARSERS
for a comprehensive mapping of querystring parameters to how they are parsed.Any additional querystring arguments and keyword arguments will be passed along to the class constructor. The querystring arguments
connect_timeout
andstream_timeout
if supplied are parsed as float values.Note
In the case of conflicting arguments, querystring arguments always win.
- async get_connection(command_name: bytes | None = None, *args: ValueT, acquire: bool = True, **kwargs: ValueT | None) Connection ¶
Gets a connection from the pool
- release(connection: Connection) None ¶
Releases the
connection
back to the pool
Connection Classes¶
coredis
- class Connection(host: str = '127.0.0.1', port: int = 6379, username: str | None = None, password: str | None = None, db: int | None = 0, stream_timeout: float | None = None, connect_timeout: float | None = None, ssl_context: SSLContext | None = None, encoding: str = 'utf-8', decode_responses: bool = False, socket_keepalive: bool | None = None, socket_keepalive_options: dict[int, int | bytes] | None = None, *, client_name: str | None = None, protocol_version: Literal[2, 3] = 3, noreply: bool = False, noevict: bool = False, notouch: bool = False)[source]¶
Bases:
BaseConnection
- async connect() None ¶
Establish a connnection to the redis server and initiate any post connect callbacks
- async create_request(command: bytes, *args: ValueT, noreply: bool | None = None, decode: ValueT | None = None, encoding: str | None = None, raise_exceptions: bool = True, timeout: float | None = None) Future[ResponseType] ¶
Send a command to the redis server
- async create_requests(commands: list[CommandInvocation], raise_exceptions: bool = True, timeout: float | None = None) list[Future[ResponseType]] ¶
Send multiple commands to the redis server
- property estimated_time_to_idle: float¶
Estimated time till the pending request queue of this connection has been cleared
- async fetch_push_message(decode: ValueT | None = None, push_message_types: set[bytes] | None = None, block: bool | None = False) ResponseType ¶
Read the next pending response
- property is_connected: bool¶
Whether the connection is established and initial handshakes were performed without error
- property lag: float¶
Returns the amount of seconds since the last request was processed if there are still in flight requests pending on this connection
- async update_tracking_client(enabled: bool, client_id: int | None = None) bool ¶
Associate this connection to
client_id
to relay any tracking notifications to.
- push_messages: asyncio.Queue[ResponseType]¶
Queue that collects any unread push message types
- tracking_client_id: int | None¶
client id that the redis server should send any redirected notifications to
- protocol_version: Literal[2, 3]¶
Whether the connection should use RESP or RESP3
- class UnixDomainSocketConnection(path: str = '', username: str | None = None, password: str | None = None, db: int = 0, stream_timeout: float | None = None, connect_timeout: float | None = None, encoding: str = 'utf-8', decode_responses: bool = False, *, client_name: str | None = None, protocol_version: Literal[2, 3] = 3, **_: ValueT)[source]¶
Bases:
BaseConnection
- async connect() None ¶
Establish a connnection to the redis server and initiate any post connect callbacks
- async create_request(command: bytes, *args: ValueT, noreply: bool | None = None, decode: ValueT | None = None, encoding: str | None = None, raise_exceptions: bool = True, timeout: float | None = None) Future[ResponseType] ¶
Send a command to the redis server
- async create_requests(commands: list[CommandInvocation], raise_exceptions: bool = True, timeout: float | None = None) list[Future[ResponseType]] ¶
Send multiple commands to the redis server
- property estimated_time_to_idle: float¶
Estimated time till the pending request queue of this connection has been cleared
- async fetch_push_message(decode: ValueT | None = None, push_message_types: set[bytes] | None = None, block: bool | None = False) ResponseType ¶
Read the next pending response
- property is_connected: bool¶
Whether the connection is established and initial handshakes were performed without error
- property lag: float¶
Returns the amount of seconds since the last request was processed if there are still in flight requests pending on this connection
- async update_tracking_client(enabled: bool, client_id: int | None = None) bool ¶
Associate this connection to
client_id
to relay any tracking notifications to.
- push_messages: asyncio.Queue[ResponseType]¶
Queue that collects any unread push message types
- tracking_client_id: int | None¶
client id that the redis server should send any redirected notifications to
- protocol_version: Literal[2, 3]¶
Whether the connection should use RESP or RESP3
- class ClusterConnection(host: str = '127.0.0.1', port: int = 6379, username: str | None = None, password: str | None = None, db: int | None = 0, stream_timeout: float | None = None, connect_timeout: float | None = None, ssl_context: SSLContext | None = None, encoding: str = 'utf-8', decode_responses: bool = False, socket_keepalive: bool | None = None, socket_keepalive_options: dict[int, int | bytes] | None = None, *, client_name: str | None = None, protocol_version: Literal[2, 3] = 3, read_from_replicas: bool = False, noreply: bool = False, noevict: bool = False, notouch: bool = False)[source]¶
Bases:
Connection
Manages TCP communication to and from a Redis server
- async connect() None ¶
Establish a connnection to the redis server and initiate any post connect callbacks
- async create_request(command: bytes, *args: ValueT, noreply: bool | None = None, decode: ValueT | None = None, encoding: str | None = None, raise_exceptions: bool = True, timeout: float | None = None) Future[ResponseType] ¶
Send a command to the redis server
- async create_requests(commands: list[CommandInvocation], raise_exceptions: bool = True, timeout: float | None = None) list[Future[ResponseType]] ¶
Send multiple commands to the redis server
- property estimated_time_to_idle: float¶
Estimated time till the pending request queue of this connection has been cleared
- async fetch_push_message(decode: ValueT | None = None, push_message_types: set[bytes] | None = None, block: bool | None = False) ResponseType ¶
Read the next pending response
- property is_connected: bool¶
Whether the connection is established and initial handshakes were performed without error
- property lag: float¶
Returns the amount of seconds since the last request was processed if there are still in flight requests pending on this connection
- async update_tracking_client(enabled: bool, client_id: int | None = None) bool ¶
Associate this connection to
client_id
to relay any tracking notifications to.
- push_messages: asyncio.Queue[ResponseType]¶
Queue that collects any unread push message types
- tracking_client_id: int | None¶
client id that the redis server should send any redirected notifications to
- protocol_version: Literal[2, 3]¶
Whether the connection should use RESP or RESP3
- class SentinelManagedConnection(connection_pool: SentinelConnectionPool, host: str = '127.0.0.1', port: int = 6379, username: str | None = None, password: str | None = None, db: int = 0, stream_timeout: float | None = None, connect_timeout: float | None = None, ssl_context: SSLContext | None = None, encoding: str = 'utf-8', decode_responses: bool = False, socket_keepalive: bool | None = None, socket_keepalive_options: dict[int, int | bytes] | None = None, *, client_name: str | None = None, protocol_version: Literal[2, 3] = 2)[source]¶
Bases:
Connection
,Generic
- async connect() None [source]¶
Establish a connnection to the redis server and initiate any post connect callbacks
- async create_request(command: bytes, *args: ValueT, noreply: bool | None = None, decode: ValueT | None = None, encoding: str | None = None, raise_exceptions: bool = True, timeout: float | None = None) Future[ResponseType] ¶
Send a command to the redis server
- async create_requests(commands: list[CommandInvocation], raise_exceptions: bool = True, timeout: float | None = None) list[Future[ResponseType]] ¶
Send multiple commands to the redis server
- property estimated_time_to_idle: float¶
Estimated time till the pending request queue of this connection has been cleared
- async fetch_push_message(decode: ValueT | None = None, push_message_types: set[bytes] | None = None, block: bool | None = False) ResponseType ¶
Read the next pending response
- property is_connected: bool¶
Whether the connection is established and initial handshakes were performed without error
- property lag: float¶
Returns the amount of seconds since the last request was processed if there are still in flight requests pending on this connection
- async update_tracking_client(enabled: bool, client_id: int | None = None) bool ¶
Associate this connection to
client_id
to relay any tracking notifications to.
- push_messages: asyncio.Queue[ResponseType]¶
Queue that collects any unread push message types
- tracking_client_id: int | None¶
client id that the redis server should send any redirected notifications to
- protocol_version: Literal[2, 3]¶
Whether the connection should use RESP or RESP3
All connection classes derive from the same base-class:
- class BaseConnection(stream_timeout: float | None = None, encoding: str = 'utf-8', decode_responses: bool = False, *, client_name: str | None = None, protocol_version: Literal[2, 3] = 3, noreply: bool = False, noevict: bool = False, notouch: bool = False)[source]¶
Bases:
BaseProtocol
Base connection class which implements
asyncio.BaseProtocol
to interact with the underlying connection established with the redis server.- protocol_version: Literal[2, 3]¶
Whether the connection should use RESP or RESP3
- tracking_client_id: int | None¶
client id that the redis server should send any redirected notifications to
- push_messages: asyncio.Queue[ResponseType]¶
Queue that collects any unread push message types
- property estimated_time_to_idle: float¶
Estimated time till the pending request queue of this connection has been cleared
- property is_connected: bool¶
Whether the connection is established and initial handshakes were performed without error
- property lag: float¶
Returns the amount of seconds since the last request was processed if there are still in flight requests pending on this connection
- async connect() None [source]¶
Establish a connnection to the redis server and initiate any post connect callbacks
- async update_tracking_client(enabled: bool, client_id: int | None = None) bool [source]¶
Associate this connection to
client_id
to relay any tracking notifications to.
- async fetch_push_message(decode: ValueT | None = None, push_message_types: set[bytes] | None = None, block: bool | None = False) ResponseType [source]¶
Read the next pending response
- async create_request(command: bytes, *args: ValueT, noreply: bool | None = None, decode: ValueT | None = None, encoding: str | None = None, raise_exceptions: bool = True, timeout: float | None = None) Future[ResponseType] [source]¶
Send a command to the redis server