buildgrid.server.redis.provider module
- class buildgrid.server.redis.provider.RedisProvider(*, host: str | None = None, port: int | None = None, password: str | None = None, db: int | None = None, dns_srv_record: str | None = None, sentinel_master_name: str | None = None, retries: int = 3)
Bases:
object
Provides and manages a Redis connection
This class manages the connection to a Redis cache.
The connection can be configured by specifying host/port or by specifying a DNS SRV record to use to discover the host/port.
If a sentinel master name is provided then it is assumed the connection is to a Redis sentinel and the master and replica clients will be obtained from the sentinel.
- Parameters:
host (str | None) – The hostname of the Redis server to use.
port (int | None) – The port that Redis is served on.
password (str | None) – The Redis database password to use.
db (int) – The Redis database number to use.
dns-srv-record (str) – Domain name of SRV record used to discover host/port
sentinel-master-name (str) – Service name of Redis master instance, used in a Redis sentinel configuration
retries (int) – Max number of times to retry (default 3). Backoff between retries is about 2^(N-1), where N is the number of attempts
- Raises:
RuntimeError – when unable to resolve a host/port to connect to
- execute_rw(func: Callable[[redis.Redis[bytes]], T]) T
Calls
func
with the redis read/write client as argument.The
func
may be called more than once if the host has changed.
- execute_ro(func: Callable[[redis.Redis[bytes]], T]) T
Calls
func
with a redis read-only client as argument.The
func
may be called more than once if the host has changed.