redis 6.4.0


pip install redis

  Latest version

Released: Aug 07, 2025


Meta
Author: Redis Inc.
Requires Python: >=3.9

Classifiers

Development Status
  • 5 - Production/Stable

Environment
  • Console

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 3
  • Python :: 3 :: Only
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

redis-py

The Python interface to the Redis key-value store.

CI docs MIT licensed pypi pre-release codecov

Installation | Usage | Advanced Topics | Contributing


Note: redis-py 5.0 will be the last version of redis-py to support Python 3.7, as it has reached end of life. redis-py 5.1 will support Python 3.8+. Note: redis-py 6.1.0 will be the last version of redis-py to support Python 3.8, as it has reached end of life. redis-py 6.2.0 will support Python 3.9+.

How do I Redis?

Learn for free at Redis University

Try the Redis Cloud

Dive in developer tutorials

Join the Redis community

Work at Redis

Installation

Start a redis via docker (for Redis versions >= 8.0):

docker run -p 6379:6379 -it redis:latest

Start a redis via docker (for Redis versions < 8.0):

docker run -p 6379:6379 -it redis/redis-stack:latest

To install redis-py, simply:

$ pip install redis

For faster performance, install redis with hiredis support, this provides a compiled response parser, and for most cases requires zero code changes. By default, if hiredis >= 1.0 is available, redis-py will attempt to use it for response parsing.

$ pip install "redis[hiredis]"

Looking for a high-level library to handle object mapping? See redis-om-python!

Supported Redis Versions

The most recent version of this library supports Redis version 7.2, 7.4 and 8.0.

The table below highlights version compatibility of the most-recent library versions and redis versions.

Library version Supported redis versions
3.5.3 <= 6.2 Family of releases
>= 4.5.0 Version 5.0 to 7.0
>= 5.0.0 Version 5.0 to 7.4
>= 6.0.0 Version 7.2 to current

Usage

Basic Example

>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0)
>>> r.set('foo', 'bar')
True
>>> r.get('foo')
b'bar'

The above code connects to localhost on port 6379, sets a value in Redis, and retrieves it. All responses are returned as bytes in Python, to receive decoded strings, set decode_responses=True. For this, and more connection options, see these examples.

RESP3 Support

To enable support for RESP3, ensure you have at least version 5.0 of the client, and change your connection object to include protocol=3

>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0, protocol=3)

Connection Pools

By default, redis-py uses a connection pool to manage connections. Each instance of a Redis class receives its own connection pool. You can however define your own redis.ConnectionPool.

>>> pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
>>> r = redis.Redis(connection_pool=pool)

Alternatively, you might want to look at Async connections, or Cluster connections, or even Async Cluster connections.

Redis Commands

There is built-in support for all of the out-of-the-box Redis commands. They are exposed using the raw Redis command names (HSET, HGETALL, etc.) except where a word (i.e. del) is reserved by the language. The complete set of commands can be found here, or the documentation.

Advanced Topics

The official Redis command documentation does a great job of explaining each command in detail. redis-py attempts to adhere to the official command syntax. There are a few exceptions:

  • MULTI/EXEC: These are implemented as part of the Pipeline class. The pipeline is wrapped with the MULTI and EXEC statements by default when it is executed, which can be disabled by specifying transaction=False. See more about Pipelines below.

  • SUBSCRIBE/LISTEN: Similar to pipelines, PubSub is implemented as a separate class as it places the underlying connection in a state where it can't execute non-pubsub commands. Calling the pubsub method from the Redis client will return a PubSub instance where you can subscribe to channels and listen for messages. You can only call PUBLISH from the Redis client (see this comment on issue #151 for details).

For more details, please see the documentation on advanced topics page.

Pipelines

The following is a basic example of a Redis pipeline, a method to optimize round-trip calls, by batching Redis commands, and receiving their results as a list.

>>> pipe = r.pipeline()
>>> pipe.set('foo', 5)
>>> pipe.set('bar', 18.5)
>>> pipe.set('blee', "hello world!")
>>> pipe.execute()
[True, True, True]

PubSub

The following example shows how to utilize Redis Pub/Sub to subscribe to specific channels.

>>> r = redis.Redis(...)
>>> p = r.pubsub()
>>> p.subscribe('my-first-channel', 'my-second-channel', ...)
>>> p.get_message()
{'pattern': None, 'type': 'subscribe', 'channel': b'my-second-channel', 'data': 1}

Redis’ search and query capabilities default dialect

Release 6.0.0 introduces a client-side default dialect for Redis’ search and query capabilities. By default, the client now overrides the server-side dialect with version 2, automatically appending DIALECT 2 to commands like FT.AGGREGATE and FT.SEARCH.

Important: Be aware that the query dialect may impact the results returned. If needed, you can revert to a different dialect version by configuring the client accordingly.

>>> from redis.commands.search.field import TextField
>>> from redis.commands.search.query import Query
>>> from redis.commands.search.index_definition import IndexDefinition
>>> import redis

>>> r = redis.Redis(host='localhost', port=6379, db=0)
>>> r.ft().create_index(
>>>     (TextField("name"), TextField("lastname")),
>>>     definition=IndexDefinition(prefix=["test:"]),
>>> )

>>> r.hset("test:1", "name", "James")
>>> r.hset("test:1", "lastname", "Brown")

>>> # Query with default DIALECT 2
>>> query = "@name: James Brown"
>>> q = Query(query)
>>> res = r.ft().search(q)

>>> # Query with explicit DIALECT 1
>>> query = "@name: James Brown"
>>> q = Query(query).dialect(1)
>>> res = r.ft().search(q)

You can find further details in the query dialect documentation.


Author

redis-py is developed and maintained by Redis Inc. It can be found here, or downloaded from pypi.

Special thanks to:

  • Andy McCurdy (sedrik@gmail.com) the original author of redis-py.
  • Ludovico Magnocavallo, author of the original Python Redis client, from which some of the socket code is still used.
  • Alexander Solovyov for ideas on the generic response callback system.
  • Paul Hubbard for initial packaging support.

Redis

7.0.0b3 Oct 07, 2025
7.0.0b2 Sep 26, 2025
7.0.0b1 Sep 09, 2025
6.4.0 Aug 07, 2025
6.3.0 Aug 05, 2025
6.2.0 May 28, 2025
6.1.1 Jun 02, 2025
6.1.0 May 13, 2025
6.0.0 Apr 30, 2025
6.0.0b2 Apr 07, 2025
6.0.0b1 Mar 24, 2025
5.3.1 Jul 25, 2025
5.3.0 Apr 30, 2025
5.3.0b5 Feb 11, 2025
5.3.0b4 Dec 23, 2024
5.3.0b3 Dec 20, 2024
5.3.0b1 Dec 20, 2024
5.2.1 Dec 06, 2024
5.2.0 Oct 24, 2024
5.1.1 Oct 04, 2024
5.1.0 Sep 27, 2024
5.1.0b7 Jun 20, 2024
5.1.0b6 Jun 06, 2024
5.1.0b5 May 08, 2024
5.1.0b4 Feb 29, 2024
5.1.0b3 Jan 15, 2024
5.1.0b2 Jan 07, 2024
5.1.0b1 Jan 01, 2024
5.1.0a1 Nov 16, 2023
5.0.8 Jul 30, 2024
5.0.7 Jun 26, 2024
5.0.6 Jun 13, 2024
5.0.5 Jun 06, 2024
5.0.4 Apr 23, 2024
5.0.3 Mar 10, 2024
5.0.2 Feb 28, 2024
5.0.1 Sep 26, 2023
5.0.0 Aug 15, 2023
5.0.0rc2 Jul 16, 2023
5.0.0rc1 Jun 27, 2023
5.0.0b4 May 28, 2023
5.0.0b3 May 04, 2023
5.0.0b2 Apr 24, 2023
5.0.0b1 Mar 23, 2023
4.6.0 Jun 25, 2023
4.5.5 May 08, 2023
4.5.4 Mar 29, 2023
4.5.3 Mar 22, 2023
4.5.2 Mar 20, 2023
4.5.1 Feb 08, 2023
4.5.0 Feb 07, 2023
4.4.4 Mar 29, 2023
4.4.3 Mar 22, 2023
4.4.2 Jan 11, 2023
4.4.1 Jan 08, 2023
4.4.0 Dec 04, 2022
4.4.0rc4 Nov 10, 2022
4.4.0rc3 Nov 08, 2022
4.4.0rc2 Sep 29, 2022
4.4.0rc1 Aug 04, 2022
4.3.6 Mar 22, 2023
4.3.5 Nov 22, 2022
4.3.4 Jun 27, 2022
4.3.3 Jun 02, 2022
4.3.2 Jun 01, 2022
4.3.1 May 09, 2022
4.3.0 May 08, 2022
4.2.2 Apr 04, 2022
4.2.1 Mar 31, 2022
4.2.0 Mar 23, 2022
4.2.0rc3 Mar 14, 2022
4.2.0rc2 Mar 08, 2022
4.2.0rc1 Feb 22, 2022
4.1.4 Feb 16, 2022
4.1.3 Feb 08, 2022
4.1.2 Jan 27, 2022
4.1.1 Jan 17, 2022
4.1.0 Dec 26, 2021
4.1.0rc2 Dec 09, 2021
4.1.0rc1 Nov 25, 2021
4.0.2 Nov 22, 2021
4.0.1 Nov 17, 2021
4.0.0 Nov 15, 2021
4.0.0rc2 Nov 09, 2021
4.0.0rc1 Nov 04, 2021
4.0.0b3 Oct 26, 2021
4.0.0b2 Oct 26, 2021
4.0.0b1 Oct 17, 2021
3.5.3 Jun 01, 2020
3.5.2 May 14, 2020
3.5.1 May 09, 2020
3.5.0 Apr 29, 2020
3.4.1 Feb 02, 2020
3.4.0 Jan 31, 2020
3.3.11 Oct 13, 2019
3.3.10 Oct 10, 2019
3.3.9 Oct 10, 2019
3.3.8 Aug 19, 2019
3.3.7 Aug 13, 2019
3.3.6 Aug 06, 2019
3.3.5 Aug 02, 2019
3.3.4 Jul 30, 2019
3.3.3 Jul 30, 2019
3.3.2 Jul 29, 2019
3.3.1 Jul 29, 2019
3.3.0 Jul 28, 2019
3.2.1 Mar 15, 2019
3.2.0 Feb 17, 2019
3.1.0 Jan 29, 2019
3.0.1 Nov 15, 2018
3.0.0.post1 Nov 15, 2018
3.0.0 Nov 15, 2018
2.10.6 Aug 16, 2017
2.10.5 Nov 03, 2015
2.10.3 Aug 14, 2014
2.10.2 Aug 11, 2014
2.10.1 Jun 02, 2014
2.10.0 Jun 02, 2014
2.9.1 Jan 23, 2014
2.9.0 Jan 02, 2014
2.8.0 Aug 23, 2013
2.7.6 Jun 14, 2013
2.7.5 May 14, 2013
2.7.4 Apr 28, 2013
2.7.3 Apr 23, 2013
2.7.2 Nov 16, 2012
2.7.1 Oct 08, 2012
2.7.0 Oct 08, 2012
2.6.2 Jun 25, 2013
2.6.1 Jun 25, 2013
2.6.0 Jun 25, 2013
2.4.13 Jun 25, 2013
2.4.12 Jun 25, 2013
2.4.11 Jun 25, 2013
2.4.10 Jun 25, 2013
2.4.9 Jun 25, 2013
2.4.8 Jun 25, 2013
2.4.7 Jun 25, 2013
2.4.6 Jun 25, 2013
2.4.5 Jun 25, 2013
2.4.4 Jun 25, 2013
2.4.3 Jun 25, 2013
2.4.2 Jun 25, 2013
2.4.1 Jun 25, 2013
2.4.0 Jun 25, 2013
2.2.4 Jun 25, 2013
2.2.2 Jun 25, 2013
2.2.0 Jun 25, 2013
2.0.0 Jun 25, 2013
1.34.1 Jun 25, 2013
1.34 Jun 25, 2013
0.6.1 Jun 25, 2013
0.6.0 Jun 25, 2013

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
async-timeout (>=4.0.3)