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

# client

# `prefect_redis.client`

## Functions

### `is_cluster_url` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect\_redis/client.py#L111](https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/client.py#L111)</sup>

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

Return True if the URL uses the Redis Cluster scheme.

### `normalize_cluster_url` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect\_redis/client.py#L116](https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/client.py#L116)</sup>

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

Return a redis-py compatible URL for Redis Cluster connections.

### `cluster_key_prefix` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect\_redis/client.py#L130](https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/client.py#L130)</sup>

```python theme={null}
cluster_key_prefix(prefix: str, url: str | None = None) -> str
```

Return a key prefix, hash-tagged when configured for Redis Cluster.

### `redis_key` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect\_redis/client.py#L138](https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/client.py#L138)</sup>

```python theme={null}
redis_key(prefix: str, suffix: str, url: str | None = None) -> str
```

Return a Redis key rooted at a cluster-aware prefix.

### `cached` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect\_redis/client.py#L160](https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/client.py#L160)</sup>

```python theme={null}
cached(fn: Callable[..., Any]) -> Callable[..., Any]
```

### `close_all_cached_connections` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect\_redis/client.py#L171](https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/client.py#L171)</sup>

```python theme={null}
close_all_cached_connections() -> None
```

Close all cached Redis connections.

Sentinel-backed clients hold one extra Redis client per Sentinel daemon, so
the daemon-aware `aclose_redis_client` is used rather than a bare
`client.aclose()`.

### `clear_cached_clients` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect\_redis/client.py#L187](https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/client.py#L187)</sup>

```python theme={null}
clear_cached_clients() -> None
```

Clear cached Redis clients and the messaging URL lookup.

### `get_async_redis_client` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect\_redis/client.py#L194](https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/client.py#L194)</sup>

```python theme={null}
get_async_redis_client(url: Union[str, None] = None, host: Union[str, None] = None, port: Union[int, None] = None, db: Union[int, None] = None, password: Union[str, None] = None, username: Union[str, None] = None, health_check_interval: Union[int, None] = None, decode_responses: bool = True, ssl: Union[bool, None] = None, socket_timeout: Union[float, None, Any] = _UNSET, socket_connect_timeout: Union[float, None, Any] = _UNSET, protocol: Union[int, None] = None) -> Redis
```

Retrieves an async Redis client.

When a `url` is provided (or configured via `PREFECT_REDIS_MESSAGING_URL`)
the discrete host/port/… arguments are ignored. Standalone URLs are passed
to `Redis.from_url`; `redis+sentinel://` and `rediss+sentinel://` URLs
resolve the current master through the listed Sentinel daemons and follow
failover automatically. URL query options override the settings-derived
connection defaults. Redis Cluster URLs are detected but intentionally not
enabled yet.

**Args:**

* `url`: Full Redis URL (e.g. `redis\://localhost\:6379/0` or
  `redis+sentinel\://sentinel-a\:26379,sentinel-b\:26379/mymaster`).
* `host`: The host location.
* `port`: The port to connect to the host with.
* `db`: The Redis database to interact with.
* `password`: The password for the redis host
* `username`: Username for the redis instance
* `health_check_interval`: Health check interval in seconds.
* `decode_responses`: Whether to decode binary responses from Redis to
  unicode strings.
* `ssl`: Whether to use SSL for the connection.
* `socket_timeout`: Timeout for socket read operations (None = no timeout).
* `socket_connect_timeout`: Timeout for socket connect (None = no timeout).
* `protocol`: RESP protocol version (default 2 from settings).

**Returns:**

* a Redis client

### `async_redis_from_settings` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect\_redis/client.py#L287](https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/client.py#L287)</sup>

```python theme={null}
async_redis_from_settings(settings: RedisMessagingSettings, **options: Any) -> Redis
```

## Classes

### `RedisMessagingSettings` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect\_redis/client.py#L20](https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-redis/prefect_redis/client.py#L20)</sup>

Settings for connecting to Redis.

Connection can be configured either via a single `url` field
(e.g. `redis://user:pass@host:6379/0`) or with the individual
`host`/`port`/`db`/… fields.  When `url` is set it takes
precedence and the discrete fields are ignored.

Environment variable: `PREFECT_REDIS_MESSAGING_URL`
