Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions content/develop/clients/redis-py/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ aliases:
- /clients/python/
- /connect/clients/redis-py/
- /clients/redis-py/
- /develop/clients/python/redis-py/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed redirect alias

Medium Severity

The front matter drops the /develop/clients/python/redis-py/ alias while keeping the other historical paths. That URL no longer redirects to the redis-py guide, so old bookmarks and inbound links 404. The sibling redis-vl page still keeps the matching /develop/clients/python/redis-vl/ alias, and the PR’s stated scope is only portable links and callouts.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ec9ca85. Configure here.

categories:
- docs
- develop
Expand All @@ -27,10 +26,10 @@ weight: 1
The sections below explain how to install `redis-py` and connect your application
to a Redis database.

`redis-py` requires a running Redis server. See [here]({{< relref "/operate/oss_and_stack/install/" >}}) for Redis Open Source installation instructions.
`redis-py` requires a running Redis server. See [here](/content/operate/oss_and_stack/install/_index.md) for Redis Open Source installation instructions.

You can also access Redis with an object-mapping client interface. See
[RedisOM for Python]({{< relref "/integrate/redisom-for-python" >}})
[RedisOM for Python](/content/integrate/redisom-for-python/_index.md)
for more information.

## Install
Expand Down
12 changes: 6 additions & 6 deletions content/develop/clients/redis-py/amr.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ letting `redis-entra-id` fetch and renew the authentication tokens for you autom

## Install

Install [`redis-py`]({{< relref "/develop/clients/redis-py#install" >}}) first,
Install [`redis-py`](/content/develop/clients/redis-py/_index.md#install) first,
if you have not already done so. Then, install `redis-entra-id` with the
following command:

Expand Down Expand Up @@ -134,11 +134,11 @@ When you have created your `CredentialProvider` instance, you are ready to
connect to AMR.
The example below shows how to pass the instance as a parameter to the standard
`RedisCluster()` connection method.
{{< note >}} Azure requires you to use
[Transport Layer Security (TLS)](https://en.wikipedia.org/wiki/Transport_Layer_Security)
when you connect (see
[Connect with TLS]({{< relref "/develop/clients/redis-py/connect#connect-to-your-production-redis-with-tls" >}}) for more information).
{{< /note >}}
> [!NOTE]
> Azure requires you to use
> [Transport Layer Security (TLS)](https://en.wikipedia.org/wiki/Transport_Layer_Security)
> when you connect (see
> [Connect with TLS](/content/develop/clients/redis-py/connect.md#connect-to-your-production-redis-with-tls) for more information).

```python
from redis import RedisCluster
Expand Down
14 changes: 7 additions & 7 deletions content/develop/clients/redis-py/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace. It mirrors the synchronous client API, so most code patterns
translate directly — you `await` commands instead of calling them.

Use the async client for I/O-bound workloads, for integration with async web
frameworks (such as [FastAPI]({{< relref "/integrate/fastapi" >}}), [Starlette](https://www.starlette.io/), [aiohttp](https://docs.aiohttp.org/en/stable/), or [Sanic](https://sanic.dev/en/), or when you need
frameworks (such as [FastAPI](/content/integrate/fastapi/_index.md), [Starlette](https://www.starlette.io/), [aiohttp](https://docs.aiohttp.org/en/stable/), or [Sanic](https://sanic.dev/en/), or when you need
to run many concurrent Redis operations from a single process. For simple
scripts, CPU-bound work, or codebases without an existing event loop, the
synchronous client is usually a better choice.
Expand Down Expand Up @@ -50,7 +50,7 @@ which ensures `aclose()` runs even if an exception is raised:

For production usage, you should manage connections with a connection pool
rather than opening and closing them individually.
See [Connection pools and multiplexing]({{< relref "/develop/clients/pools-and-muxing" >}})
See [Connection pools and multiplexing](/content/develop/clients/pools-and-muxing.md)
for more information about how this works.

A `Redis` client instance already creates and manages its own connection
Expand Down Expand Up @@ -93,7 +93,7 @@ through a single connection instead.)
## Pipelines and transactions

Pipelines and transactions work the same way as in the synchronous client
(see [Pipelines and transactions]({{< relref "/develop/clients/redis-py/transpipe" >}})
(see [Pipelines and transactions](/content/develop/clients/redis-py/transpipe.md)
for the conceptual background). The only difference is that you create the
pipeline inside an `async with` block and `await pipe.execute()`.

Expand Down Expand Up @@ -125,7 +125,7 @@ consuming task its own subscription.

To connect to a Redis cluster asynchronously, import `RedisCluster` from
`redis.asyncio.cluster`. The API matches the synchronous cluster client
(see [Connect to a Redis cluster]({{< relref "/develop/clients/redis-py/connect#connect-to-a-redis-cluster" >}})),
(see [Connect to a Redis cluster](/content/develop/clients/redis-py/connect.md#connect-to-a-redis-cluster)),
with `await` in front of each command.

{{< clients-example set="async_intro" step="cluster" lang_filter="Python" description="Foundational: Connect to a Redis cluster with the async client" difficulty="beginner" >}}
Expand All @@ -139,7 +139,7 @@ Always close clients and pools when you're done:
single scope.
- For longer-lived clients, call `await r.aclose()` explicitly. (The older
`close()` method is deprecated.)
- For frameworks with startup/shutdown hooks — for example [FastAPI]({{< relref "/integrate/fastapi" >}})'s
- For frameworks with startup/shutdown hooks — for example [FastAPI](/content/integrate/fastapi/_index.md)'s
`lifespan` — create the client or pool at startup and close it at
shutdown so connections aren't leaked between process restarts.

Expand Down Expand Up @@ -178,6 +178,6 @@ client, apply these rules:

- The [`redis-py` asyncio examples](https://redis.readthedocs.io/en/stable/examples/asyncio_examples.html)
on Read the Docs cover further patterns.
- See [Error handling]({{< relref "/develop/clients/redis-py/error-handling" >}}) and
[Client-side geographic failover]({{< relref "/develop/clients/redis-py/failover" >}}) for
- See [Error handling](/content/develop/clients/redis-py/error-handling.md) and
[Client-side geographic failover](/content/develop/clients/redis-py/failover.md) for
resiliency patterns that apply to both sync and async clients.
66 changes: 33 additions & 33 deletions content/develop/clients/redis-py/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ For more information, see [redis-py Clustering](https://redis.readthedocs.io/en/

## Connect to your production Redis with TLS

When you deploy your application, use TLS and follow the [Redis security]({{< relref "/operate/oss_and_stack/management/security/" >}}) guidelines.
When you deploy your application, use TLS and follow the [Redis security](/content/operate/oss_and_stack/management/security/_index.md) guidelines.

```python
import redis
Expand All @@ -95,14 +95,14 @@ For more information, see [redis-py TLS examples](https://redis.readthedocs.io/e

Client-side caching is a technique to reduce network traffic between
the client and server, resulting in better performance. See
[Client-side caching introduction]({{< relref "/develop/clients/client-side-caching" >}})
[Client-side caching introduction](/content/develop/clients/client-side-caching.md)
for more information about how client-side caching works and how to use it effectively.

To enable client-side caching, add some extra parameters when you connect
to the server:

- `protocol`: (Required) You must pass a value of `3` here because
client-side caching requires the [RESP3]({{< relref "/develop/reference/protocol-spec#resp-versions" >}})
client-side caching requires the [RESP3](/content/develop/reference/protocol-spec.md#resp-versions)
protocol.
- `cache_config`: (Required) Pass `cache_config=CacheConfig()` here to enable client-side caching.

Expand All @@ -111,15 +111,15 @@ The example below shows the simplest client-side caching connection to the defau
All of the connection variants described above accept these parameters, so you can
use client-side caching with a connection pool or a cluster connection in exactly the same way.

{{< note >}}Client-side caching requires redis-py v5.1.0 or later.
To maximize compatibility with all Redis products, client-side caching
is supported by Redis v7.4 or later.

The [Redis server products]({{< relref "/operate" >}}) support
[opt-in/opt-out]({{< relref "/develop/reference/client-side-caching#opt-in-and-opt-out-caching" >}}) mode
and [broadcasting mode]({{< relref "/develop/reference/client-side-caching#broadcasting-mode" >}})
for CSC, but these modes are not currently implemented by `redis-py`.
{{< /note >}}
> [!NOTE]
> Client-side caching requires redis-py v5.1.0 or later.
> To maximize compatibility with all Redis products, client-side caching
> is supported by Redis v7.4 or later.
>
> The [Redis server products](/content/operate/_index.md) support
> [opt-in/opt-out](/content/develop/reference/client-side-caching.md#opt-in-and-opt-out-caching) mode
> and [broadcasting mode](/content/develop/reference/client-side-caching.md#broadcasting-mode)
> for CSC, but these modes are not currently implemented by `redis-py`.

```python
import redis
Expand All @@ -137,8 +137,8 @@ cityNameAttempt2 = r.get("city") # Retrieved from cache
```

You can see the cache working if you connect to the same Redis database
with [`redis-cli`]({{< relref "/develop/tools/cli" >}}) and run the
[`MONITOR`]({{< relref "/commands/monitor" >}}) command. If you run the
with [`redis-cli`](/content/develop/tools/cli.md) and run the
[`MONITOR`](/content/commands/monitor.md) command. If you run the
code above with the `cache_config` line commented out, you should see
the following in the CLI among the output from `MONITOR`:

Expand All @@ -164,8 +164,8 @@ call was satisfied by the cache.
You can remove individual keys from the cache with the
`delete_by_redis_keys()` method. This removes all cached items associated
with the keys, so all results from multi-key commands (such as
[`MGET`]({{< relref "/commands/mget" >}})) and composite data structures
(such as [hashes]({{< relref "/develop/data-types/hashes" >}})) will be
[`MGET`](/content/commands/mget.md)) and composite data structures
(such as [hashes](/content/develop/data-types/hashes.md)) will be
cleared at once. The example below shows the effect of removing a single
key from the cache:

Expand Down Expand Up @@ -219,7 +219,7 @@ one of its open connections. When you subsequently close the same connection,
it is not actually closed but simply returned to the pool for reuse.
This avoids the overhead of repeated connecting and disconnecting.
See
[Connection pools and multiplexing]({{< relref "/develop/clients/pools-and-muxing" >}})
[Connection pools and multiplexing](/content/develop/clients/pools-and-muxing.md)
for more information.

Use the following code to connect with a connection pool:
Expand Down Expand Up @@ -250,7 +250,7 @@ network outage or a server that is temporarily unavailable. In these cases,
retrying the connection after a short delay will usually succeed. `redis-py` uses
a simple retry strategy by default, but there are various ways you can customize
this behavior to suit your use case. See
[Retries]({{< relref "/develop/clients/redis-py/produsage#retries" >}})
[Retries](/content/develop/clients/redis-py/produsage.md#retries)
for more information about custom retry strategies, with example code.

## Connect using Smart client handoffs (SCH)
Expand All @@ -259,13 +259,13 @@ for more information about custom retry strategies, with example code.
Redis Software servers that lets them actively notify clients
about planned server maintenance shortly before it happens. This
lets a client take action to avoid disruptions in service.
See [Smart client handoffs]({{< relref "/develop/clients/sch" >}})
See [Smart client handoffs](/content/develop/clients/sch.md)
for more information about SCH.

{{< note >}}Using SCH with redis-py requires v7.0.0 or later for
basic connections, and v7.2.0 or later for
[OSS Cluster API]({{< relref "/operate/rs/databases/configure/oss-cluster-api" >}}) connections.
{{< /note >}}
> [!NOTE]
> Using SCH with redis-py requires v7.0.0 or later for
> basic connections, and v7.2.0 or later for
> [OSS Cluster API](/content/operate/rs/databases/configure/oss-cluster-api.md) connections.

By default, `redis-py` always attempts to connect via SCH but falls back to
a non-SCH connection if the server doesn't support it. However, you can configure SCH
Expand Down Expand Up @@ -299,9 +299,9 @@ r = redis.Redis(
)
```

{{< note >}}SCH requires the [RESP3]({{< relref "/develop/reference/protocol-spec#resp-versions" >}})
protocol, so you must set `protocol=3` explicitly when you connect.
{{< /note >}}
> [!NOTE]
> SCH requires the [RESP3](/content/develop/reference/protocol-spec.md#resp-versions)
> protocol, so you must set `protocol=3` explicitly when you connect.

The `MaintNotificationsConfig` constructor accepts the following parameters:

Expand All @@ -312,10 +312,10 @@ The `MaintNotificationsConfig` constructor accepts the following parameters:
| `endpoint_type` | `EndpointType` | Auto-detect | The type of endpoint to use for the connection. The options are `EndpointType.EXTERNAL_IP`, `EndpointType.INTERNAL_IP`, `EndpointType.EXTERNAL_FQDN`, `EndpointType.INTERNAL_FQDN`, and `EndpointType.NONE`. |
| `relaxed_timeout` | `int` | `20` | The timeout (in seconds) to use while the server is performing maintenance. A value of `-1` disables the relax timeout and just uses the normal timeout during maintenance. |

{{< note >}} Redis Cloud supports relaxed timeouts *only* (and not pre-handoffs) for SCH if you are using
either [AWS PrivateLink]({{< relref "/operate/rc/security/aws-privatelink" >}}) or
[Google Cloud Private Service Connect]({{< relref "/operate/rc/security/private-service-connect" >}})
(see [Smart client handoffs]({{< relref "/develop/clients/sch#redis-cloud" >}}) for more information).
To use relaxed timeouts with these services, you should set `endpoint_type=EndpointType.NONE`
when you connect. All other configurations have full support for both relaxed timeouts and pre-handoffs.
{{< /note >}}
> [!NOTE]
> Redis Cloud supports relaxed timeouts *only* (and not pre-handoffs) for SCH if you are using
> either [AWS PrivateLink](/content/operate/rc/security/aws-privatelink.md) or
> [Google Cloud Private Service Connect](/content/operate/rc/security/private-service-connect.md)
> (see [Smart client handoffs](/content/develop/clients/sch.md#redis-cloud) for more information).
> To use relaxed timeouts with these services, you should set `endpoint_type=EndpointType.NONE`
> when you connect. All other configurations have full support for both relaxed timeouts and pre-handoffs.
22 changes: 11 additions & 11 deletions content/develop/clients/redis-py/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ shows the "happy path" in code examples and omits error handling for brevity.
This page explains how
redis-py's error handling works and how to apply common error handling patterns.
For an overview of error types and handling strategies, see
[Error handling]({{< relref "/develop/clients/error-handling" >}}).
See also [Production usage]({{< relref "/develop/clients/redis-py/produsage" >}})
[Error handling](/content/develop/clients/error-handling.md).
See also [Production usage](/content/develop/clients/redis-py/produsage.md)
for more information on connection management, timeouts, and other aspects of
app reliability.

Expand Down Expand Up @@ -47,7 +47,7 @@ redis-py organizes exceptions in a hierarchy. The base exception is `redis.Redis

The following exceptions are the most commonly encountered in redis-py applications.
See
[Categories of errors]({{< relref "/develop/clients/error-handling#categories-of-errors" >}})
[Categories of errors](/content/develop/clients/error-handling.md#categories-of-errors)
for a more detailed discussion of these errors and their causes.

| Exception | When it occurs | Recoverable | Recommended action |
Expand All @@ -59,14 +59,14 @@ for a more detailed discussion of these errors and their causes.

## Applying error handling patterns

The [Error handling]({{< relref "/develop/clients/error-handling" >}}) overview
The [Error handling](/content/develop/clients/error-handling.md) overview
describes four main patterns. The sections below show how to implement them in
redis-py:

### Pattern 1: Fail fast

Catch specific exceptions that represent unrecoverable errors and re-raise them (see
[Pattern 1: Fail fast]({{< relref "/develop/clients/error-handling#pattern-1-fail-fast" >}})
[Pattern 1: Fail fast](/content/develop/clients/error-handling.md#pattern-1-fail-fast)
for a full description):

```python
Expand All @@ -84,7 +84,7 @@ except redis.ResponseError:
### Pattern 2: Graceful degradation

Catch connection errors and fall back to an alternative (see
[Pattern 2: Graceful degradation]({{< relref "/develop/clients/error-handling#pattern-2-graceful-degradation" >}})
[Pattern 2: Graceful degradation](/content/develop/clients/error-handling.md#pattern-2-graceful-degradation)
for a full description):

```python
Expand All @@ -102,18 +102,18 @@ return database.get(key)
### Pattern 3: Retry with backoff

Retry on temporary errors like timeouts (see
[Pattern 3: Retry with backoff]({{< relref "/develop/clients/error-handling#pattern-3-retry-with-backoff" >}})
[Pattern 3: Retry with backoff](/content/develop/clients/error-handling.md#pattern-3-retry-with-backoff)
for a full description). redis-py has built-in retry logic
which is highly configurable. You can customize the retry strategy
(or supply your own custom strategy) and you can also specify which errors
should be retried. See
[Production usage]({{< relref "/develop/clients/redis-py/produsage#retries" >}})
[Production usage](/content/develop/clients/redis-py/produsage.md#retries)
for more information.

### Pattern 4: Log and continue

Log non-critical errors and continue (see
[Pattern 4: Log and continue]({{< relref "/develop/clients/error-handling#pattern-4-log-and-continue" >}})
[Pattern 4: Log and continue](/content/develop/clients/error-handling.md#pattern-4-log-and-continue)
for a full description):

```python
Expand Down Expand Up @@ -145,5 +145,5 @@ async def get_with_fallback(key):

## See also

- [Error handling]({{< relref "/develop/clients/error-handling" >}})
- [Production usage]({{< relref "/develop/clients/redis-py/produsage" >}})
- [Error handling](/content/develop/clients/error-handling.md)
- [Production usage](/content/develop/clients/redis-py/produsage.md)
Loading
Loading