---
title: "Redis"
description: "Learn how to set up Sentry's Redis integration and how to capture Redis commands as breadcrumbs."
url: https://docs.sentry.io/platforms/python/integrations/redis/
---

# Redis | Sentry for Python

If you're using stream mode, this page's references to "transaction" should be applied to service spans instead. See [Streamed Spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md) for more information.

## [Prerequisites](https://docs.sentry.io/platforms/python/integrations/redis.md#prerequisites)

You need:

* A Sentry [account](https://sentry.io/signup/) and [project](https://docs.sentry.io/product/projects.md)
* Your application up and running
* Python `3.6+`

## [Install & Configure](https://docs.sentry.io/platforms/python/integrations/redis.md#install--configure)

Follow our [quick start guide](https://docs.sentry.io/platforms/python.md) to set up Sentry in your Python application (make sure to enable tracing). Sentry's Redis integration is enabled automatically if you have the `redis` package installed.

The following information will be available to you on Sentry:

* Performance information about requests to Redis will be available in the waterfall diagram in the [Traces](https://sentry.io/orgredirect/organizations/:orgslug/explore/traces/) section on Sentry.
* Redis commands will be added as [breadcrumbs](https://docs.sentry.io/product/issues/issue-details/breadcrumbs.md).
* If `send_default_pii` is set to `True` in your app's `sentry_sdk.init()` call, you will also see the data used in your Redis commands.
* Sentry will never collect data of the `AUTH` command.

## [Verify Your Setup](https://docs.sentry.io/platforms/python/integrations/redis.md#verify-your-setup)

To verify that Sentry captures your Redis commands, add this code to your app, which will create a transaction called `testing_sentry` in the [Traces](https://sentry.io/orgredirect/organizations/:orgslug/explore/traces/) section:

### [Standard Redis](https://docs.sentry.io/platforms/python/integrations/redis.md#standard-redis)

```python
import redis

def main():
    sentry_sdk.init(...)  # same as above
    r = redis.Redis(host='localhost', port=6379, decode_responses=True)

    # or sentry_sdk.traces.start_span(name="testing_sentry", parent_span=None) in stream mode
    with sentry_sdk.start_transaction(name="testing_sentry"):
        r.set("foo", "bar")
        r.get("foo")

main()
```

### [Redis Cluster](https://docs.sentry.io/platforms/python/integrations/redis.md#redis-cluster)

```python
from redis.cluster import RedisCluster

def main():
    sentry_sdk.init(...)  # same as above
    rc = RedisCluster(host='localhost', port=16379)

    # or sentry_sdk.traces.start_span(name="testing_sentry", parent_span=None) in stream mode
    with sentry_sdk.start_transaction(name="testing_sentry"):
        rc.set("foo", "bar")
        rc.get("foo")

main()
```

### [Async Redis client](https://docs.sentry.io/platforms/python/integrations/redis.md#async-redis-client)

```python
import asyncio
import redis.asyncio as redis

async def main():
    sentry_sdk.init(...)  # same as above
    r = redis.Redis(host='localhost', port=6379)

    # or sentry_sdk.traces.start_span(name="testing_sentry", parent_span=None) in stream mode
    with sentry_sdk.start_transaction(name="testing_sentry"):
        await r.set("foo", "bar")
        await r.get("foo")

asyncio.run(main())
```

## [Options](https://docs.sentry.io/platforms/python/integrations/redis.md#options)

Add `RedisIntegration` explicitly to your `sentry_sdk.init()` call to set options for `RedisIntegration` to change its behavior:

```python
import sentry_sdk
from sentry_sdk.integrations.redis import RedisIntegration

sentry_sdk.init(
    # ...
    integrations=[
        RedisIntegration(
            max_data_size=None,
            cache_prefixes=["mycache", "template.cache"],
        ),
    ],
)
```

You can pass the following keyword arguments to `RedisIntegration()`:

### [max\_data\_size](https://docs.sentry.io/platforms/python/integrations/redis.md#max_data_size)

| Type    | `int`  |
| ------- | ------ |
| Default | `1024` |

Set `max_data_size` to an integer to control how many characters should be collected. When you set this option to a value that evaluates to `False` (like `0` or `None`), no trimming will take place, and the entire Redis command will be recorded.

By default, the integration trims data collected after `1024` characters.

### [cache\_prefixes](https://docs.sentry.io/platforms/python/integrations/redis.md#cache_prefixes)

| Type | `list[string]` |
| ---- | -------------- |

Specify a list of prefixes for Redis keys to define a key space to consider as cache. Cache keys will show up in the cache-monitoring dashboard, giving you more insight into your caching strategy.

For example, if you set `cache_prefixes=["template.cache", "middleware.cache"]`, then access to all Redis keys starting with `template.cache` or `middleware.cache` will show up in your cache-monitoring dashboard.

## [Next Steps](https://docs.sentry.io/platforms/python/integrations/redis.md#next-steps)

At this point, you should have integrated Sentry into your application and should already be sending data to your Sentry project.

Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:

* Explore [practical guides](https://docs.sentry.io/get-started/guides.md) on what to monitor, log, track, and investigate after setup
* Continue to [customize your configuration](https://docs.sentry.io/platforms/python/configuration.md)
* Learn more about [manually capturing errors or messages](https://docs.sentry.io/platforms/python/usage.md)
* Dive straight into the API with our [API docs](https://getsentry.github.io/sentry-python/)

Are you having problems setting up the SDK or integration?

* Find various topics in [Troubleshooting](https://docs.sentry.io/platforms/python/troubleshooting.md)
* [Get support](https://www.sentry.help/en/)
