{"id":13419604,"url":"https://github.com/redis/redis-py","last_synced_at":"2026-03-06T20:04:49.944Z","repository":{"id":716142,"uuid":"363150","full_name":"redis/redis-py","owner":"redis","description":"Redis Python client","archived":false,"fork":false,"pushed_at":"2025-05-02T12:48:14.000Z","size":9882,"stargazers_count":13016,"open_issues_count":233,"forks_count":2581,"subscribers_count":328,"default_branch":"master","last_synced_at":"2025-05-05T07:09:21.329Z","etag":null,"topics":["python","redis","redis-client","redis-cluster","redis-py"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2009-11-06T10:22:26.000Z","updated_at":"2025-05-04T15:55:26.000Z","dependencies_parsed_at":"2023-07-05T21:32:21.818Z","dependency_job_id":"a7a405f8-7bbd-4464-bb32-aba5cbf2b1c5","html_url":"https://github.com/redis/redis-py","commit_stats":{"total_commits":2117,"total_committers":450,"mean_commits":4.704444444444444,"dds":0.7453944260746339,"last_synced_commit":"9dfaeae4c328acdad76fc0d86c4d2abf78c53b95"},"previous_names":["andymccurdy/redis-py"],"tags_count":132,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fredis-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fredis-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fredis-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fredis-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis","download_url":"https://codeload.github.com/redis/redis-py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252466612,"owners_count":21752396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","redis","redis-client","redis-cluster","redis-py"],"created_at":"2024-07-30T22:01:18.292Z","updated_at":"2025-12-11T21:04:29.476Z","avatar_url":"https://github.com/redis.png","language":"Python","readme":"# redis-py\n\nThe Python interface to the Redis key-value store.\n\n[![CI](https://github.com/redis/redis-py/workflows/CI/badge.svg?branch=master)](https://github.com/redis/redis-py/actions?query=workflow%3ACI+branch%3Amaster)\n[![docs](https://readthedocs.org/projects/redis/badge/?version=stable\u0026style=flat)](https://redis.readthedocs.io/en/stable/)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n[![pypi](https://badge.fury.io/py/redis.svg)](https://pypi.org/project/redis/)\n[![pre-release](https://img.shields.io/github/v/release/redis/redis-py?include_prereleases\u0026label=latest-prerelease)](https://github.com/redis/redis-py/releases)\n[![codecov](https://codecov.io/gh/redis/redis-py/branch/master/graph/badge.svg?token=yenl5fzxxr)](https://codecov.io/gh/redis/redis-py)\n\n[Installation](#installation) |  [Usage](#usage) | [Advanced Topics](#advanced-topics) | [Contributing](https://github.com/redis/redis-py/blob/master/CONTRIBUTING.md)\n\n---------------------------------------------\n\n**Note:** redis-py 5.0 is the last version of redis-py that supports Python 3.7, as it has reached [end of life](https://devguide.python.org/versions/). redis-py 5.1 supports Python 3.8+.\u003cbr\u003e\n**Note:** redis-py 6.1.0 is the last version of redis-py that supports Python 3.8, as it has reached [end of life](https://devguide.python.org/versions/). redis-py 6.2.0 supports Python 3.9+.\n\n---------------------------------------------\n\n## How do I Redis?\n\n[Learn for free at Redis University](https://redis.io/learn/university)\n\n[Try the Redis Cloud](https://redis.io/try-free/)\n\n[Dive in developer tutorials](https://redis.io/learn)\n\n[Join the Redis community](https://redis.io/community/)\n\n[Work at Redis](https://redis.io/careers/)\n\n## Installation\n\nStart a redis via docker (for Redis versions \u003e= 8.0):\n\n``` bash\ndocker run -p 6379:6379 -it redis:latest\n```\n\nStart a redis via docker (for Redis versions \u003c 8.0):\n\n``` bash\ndocker run -p 6379:6379 -it redis/redis-stack:latest\n```\nTo install redis-py, simply:\n\n``` bash\n$ pip install redis\n```\n\nFor faster performance, install redis with hiredis support, this provides a compiled response parser, and *for most cases* requires zero code changes.\nBy default, if hiredis \u003e= 1.0 is available, redis-py will attempt to use it for response parsing.\n\n``` bash\n$ pip install \"redis[hiredis]\"\n```\n\nLooking for a high-level library to handle object mapping? See [redis-om-python](https://github.com/redis/redis-om-python)!\n\n## Supported Redis Versions\n\nThe most recent version of this library supports Redis version [7.2](https://github.com/redis/redis/blob/7.2/00-RELEASENOTES), [7.4](https://github.com/redis/redis/blob/7.4/00-RELEASENOTES), [8.0](https://github.com/redis/redis/blob/8.0/00-RELEASENOTES) and [8.2](https://github.com/redis/redis/blob/8.2/00-RELEASENOTES).\n\nThe table below highlights version compatibility of the most-recent library versions and redis versions.\n\n| Library version | Supported redis versions |\n|-----------------|-------------------|\n| 3.5.3 | \u003c= 6.2 Family of releases |\n| \u003e= 4.5.0 | Version 5.0 to 7.0 |\n| \u003e= 5.0.0 | Version 5.0 to 7.4 |\n| \u003e= 6.0.0 | Version 7.2 to current |\n\n\n## Usage\n\n### Basic Example\n\n``` python\n\u003e\u003e\u003e import redis\n\u003e\u003e\u003e r = redis.Redis(host='localhost', port=6379, db=0)\n\u003e\u003e\u003e r.set('foo', 'bar')\nTrue\n\u003e\u003e\u003e r.get('foo')\nb'bar'\n```\n\nThe 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](https://redis.readthedocs.io/en/stable/examples.html).\n\n\n#### RESP3 Support\nTo enable support for RESP3, ensure you have at least version 5.0 of the client, and change your connection object to include *protocol=3*\n\n``` python\n\u003e\u003e\u003e import redis\n\u003e\u003e\u003e r = redis.Redis(host='localhost', port=6379, db=0, protocol=3)\n```\n\n### Connection Pools\n\nBy 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](https://redis.readthedocs.io/en/stable/connections.html#connection-pools).\n\n``` python\n\u003e\u003e\u003e pool = redis.ConnectionPool(host='localhost', port=6379, db=0)\n\u003e\u003e\u003e r = redis.Redis(connection_pool=pool)\n```\n\nAlternatively, you might want to look at [Async connections](https://redis.readthedocs.io/en/stable/examples/asyncio_examples.html), or [Cluster connections](https://redis.readthedocs.io/en/stable/connections.html#cluster-client), or even [Async Cluster connections](https://redis.readthedocs.io/en/stable/connections.html#async-cluster-client).\n\n### Redis Commands\n\nThere is built-in support for all of the [out-of-the-box Redis commands](https://redis.io/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](https://github.com/redis/redis-py/tree/master/redis/commands), or [the documentation](https://redis.readthedocs.io/en/stable/commands.html).\n\n## Advanced Topics\n\nThe [official Redis command documentation](https://redis.io/commands)\ndoes a great job of explaining each command in detail. redis-py attempts\nto adhere to the official command syntax. There are a few exceptions:\n\n-   **MULTI/EXEC**: These are implemented as part of the Pipeline class.\n    The pipeline is wrapped with the MULTI and EXEC statements by\n    default when it is executed, which can be disabled by specifying\n    transaction=False. See more about Pipelines below.\n\n-   **SUBSCRIBE/LISTEN**: Similar to pipelines, PubSub is implemented as\n    a separate class as it places the underlying connection in a state\n    where it can\\'t execute non-pubsub commands. Calling the pubsub\n    method from the Redis client will return a PubSub instance where you\n    can subscribe to channels and listen for messages. You can only call\n    PUBLISH from the Redis client (see [this comment on issue\n    #151](https://github.com/redis/redis-py/issues/151#issuecomment-1545015)\n    for details).\n\nFor more details, please see the documentation on [advanced topics page](https://redis.readthedocs.io/en/stable/advanced_features.html).\n\n### Pipelines\n\nThe following is a basic example of a [Redis pipeline](https://redis.io/docs/manual/pipelining/), a method to optimize round-trip calls, by batching Redis commands, and receiving their results as a list.\n\n\n``` python\n\u003e\u003e\u003e pipe = r.pipeline()\n\u003e\u003e\u003e pipe.set('foo', 5)\n\u003e\u003e\u003e pipe.set('bar', 18.5)\n\u003e\u003e\u003e pipe.set('blee', \"hello world!\")\n\u003e\u003e\u003e pipe.execute()\n[True, True, True]\n```\n\n### PubSub\n\nThe following example shows how to utilize [Redis Pub/Sub](https://redis.io/docs/manual/pubsub/) to subscribe to specific channels.\n\n``` python\n\u003e\u003e\u003e r = redis.Redis(...)\n\u003e\u003e\u003e p = r.pubsub()\n\u003e\u003e\u003e p.subscribe('my-first-channel', 'my-second-channel', ...)\n\u003e\u003e\u003e p.get_message()\n{'pattern': None, 'type': 'subscribe', 'channel': b'my-second-channel', 'data': 1}\n```\n\n### Redis’ search and query capabilities default dialect\n\nRelease 6.0.0 introduces a client-side default dialect for Redis’ search and query capabilities.\nBy default, the client now overrides the server-side dialect with version 2, automatically appending *DIALECT 2* to commands like *FT.AGGREGATE* and *FT.SEARCH*.\n\n**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.\n\n``` python\n\u003e\u003e\u003e from redis.commands.search.field import TextField\n\u003e\u003e\u003e from redis.commands.search.query import Query\n\u003e\u003e\u003e from redis.commands.search.index_definition import IndexDefinition\n\u003e\u003e\u003e import redis\n\n\u003e\u003e\u003e r = redis.Redis(host='localhost', port=6379, db=0)\n\u003e\u003e\u003e r.ft().create_index(\n\u003e\u003e\u003e     (TextField(\"name\"), TextField(\"lastname\")),\n\u003e\u003e\u003e     definition=IndexDefinition(prefix=[\"test:\"]),\n\u003e\u003e\u003e )\n\n\u003e\u003e\u003e r.hset(\"test:1\", \"name\", \"James\")\n\u003e\u003e\u003e r.hset(\"test:1\", \"lastname\", \"Brown\")\n\n\u003e\u003e\u003e # Query with default DIALECT 2\n\u003e\u003e\u003e query = \"@name: James Brown\"\n\u003e\u003e\u003e q = Query(query)\n\u003e\u003e\u003e res = r.ft().search(q)\n\n\u003e\u003e\u003e # Query with explicit DIALECT 1\n\u003e\u003e\u003e query = \"@name: James Brown\"\n\u003e\u003e\u003e q = Query(query).dialect(1)\n\u003e\u003e\u003e res = r.ft().search(q)\n```\n\nYou can find further details in the [query dialect documentation](https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/dialects/).\n\n### Multi-database client (Active-Active)\n\nThe multi-database client allows your application to connect to multiple Redis databases, which are typically replicas of each other. It is designed to work with Redis Software and Redis Cloud Active-Active setups. The client continuously monitors database health, detects failures, and automatically fails over to the next healthy database using a configurable strategy. When the original database becomes healthy again, the client can automatically switch back to it.\u003cbr\u003e\nThis is useful when:\n\n1. You have more than one Redis deployment. This might include two independent Redis servers or two or more Redis databases replicated across multiple [active-active Redis Enterprise](https://redis.io/docs/latest/operate/rs/databases/active-active/) clusters.\n2. You want your application to connect to one deployment at a time and to fail over to the next available deployment if the first deployment becomes unavailable.\n\nFor the complete failover configuration options and examples, see the [Multi-database client docs](https://redis.readthedocs.io/en/latest/multi_database.html).\n\n---------------------------------------------\n\n### Author\n\nredis-py is developed and maintained by [Redis Inc](https://redis.io). It can be found [here](\nhttps://github.com/redis/redis-py), or downloaded from [pypi](https://pypi.org/project/redis/).\n\nSpecial thanks to:\n\n-   Andy McCurdy (\u003csedrik@gmail.com\u003e) the original author of redis-py.\n-   Ludovico Magnocavallo, author of the original Python Redis client,\n    from which some of the socket code is still used.\n-   Alexander Solovyov for ideas on the generic response callback\n    system.\n-   Paul Hubbard for initial packaging support.\n\n[![Redis](./docs/_static/logo-redis.svg)](https://redis.io)\n","funding_links":[],"categories":["Python","Database","Data Management \u0026 Processing","数据库驱动程序","Clients","其他__大数据","数据库 Drivers","Database Clients","best open source projects for beginner","Database Drivers","📚 فهرست","Resources","Libraries"],"sub_categories":["Database Drivers","Database \u0026 Cloud Management","Python","网络服务_其他","دیتابیس","ASGI Servers","Database"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis%2Fredis-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis%2Fredis-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis%2Fredis-py/lists"}