Skip to main content

prefect_redis.connection

Redis client construction from connection URLs, including Redis Sentinel. redis-py already parses standalone redis:// and rediss:// URLs (Redis.from_url) and handles Sentinel master discovery and failover (redis.sentinel.Sentinel), but it has no URL form for a Sentinel topology. This module adds that one convention and otherwise defers to redis-py:: redis+sentinel://[user:pass@]host[:port][,host2[:port2],…]/service_name[/db][?options] rediss+sentinel://… (TLS for both the data nodes and the Sentinel daemons) Sentinel members default to port 26379. The sentinel_username and sentinel_password options authenticate to the Sentinel daemons; every other option is a standard redis-py URL option applied to the data-node connections with redis-py’s own parsing, and on a TLS scheme the ssl_* options (from the URL or from caller defaults) are shared with the daemon connections so one private CA covers the whole topology. The grammar is the one docket accepts for PREFECT_SERVER_DOCKET_URL, so a single URL serves both.

Functions

is_sentinel_url

Return True if the URL uses a Redis Sentinel scheme. Only the scheme is inspected: urlsplit rejects a member list with an IPv6 host (redis+sentinel://s1:26379,[::1]:26379/mymaster) as an invalid IPv6 URL. Schemes are matched case-insensitively per RFC 3986.

redis_from_url

Build a Redis client from a connection URL. Standalone URLs are handed to Redis.from_url unchanged. Sentinel URLs resolve the current master through the listed Sentinel daemons, and the returned client follows failover automatically. In both cases kwargs are connection defaults that URL query options override, as with Redis.from_url. Building a client is lazy and opens no connection. Close it with close_redis_client / aclose_redis_client so a Sentinel-backed client’s daemon connections are released too. Raises:
  • ValueError: If the URL is malformed. Messages do not echo the URL, so credentials embedded in it are never leaked.

close_redis_client

Close a sync client returned by redis_from_url. A Sentinel-backed client holds one extra Redis client per Sentinel daemon on its connection pool’s sentinel_manager; closing only the returned client would leave those daemon connections to be reclaimed by the garbage collector (emitting ResourceWarnings). This closes both.

aclose_redis_client

Async counterpart of close_redis_client.