> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prefect.io/llms.txt
> Use this file to discover all available pages before exploring further.

# connection

# `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` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/connection.py#L37" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
is_sentinel_url(url: str) -> bool
```

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` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/connection.py#L59" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
redis_from_url(url: str, **kwargs: Any) -> redis.Redis | redis.asyncio.Redis
```

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` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/connection.py#L208" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
close_redis_client(client: redis.Redis) -> None
```

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 `ResourceWarning`s). This closes both.

### `aclose_redis_client` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/connection.py#L223" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
aclose_redis_client(client: redis.asyncio.Redis) -> None
```

Async counterpart of `close_redis_client`.
