explaingit

redis/redis-py

13,529PythonAudience · developerComplexity · 2/5Setup · easy

TLDR

The official Python library for connecting to a Redis server, letting you store and retrieve data, use data structures like lists and sets, run pub/sub messaging, and work with Redis clusters in a few lines of code.

Mindmap

mindmap
  root((redis-py))
    What It Does
      Connect to Redis
      Store and fetch data
      Message passing
    Data Structures
      Strings and hashes
      Lists and sets
      Sorted sets
    Features
      Async support
      Command pipelines
      Pub and Sub
      Cluster mode
    Install
      pip install redis
      Optional hiredis
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Cache expensive database query results in Redis from your Python app so repeated requests are served instantly from memory.

USE CASE 2

Use Redis pub/sub to pass messages between different parts of a Python application or between microservices without a message broker.

USE CASE 3

Pipeline multiple Redis commands into a single round trip to speed up bulk data operations.

USE CASE 4

Use the async client with Python asyncio to handle many Redis operations concurrently in a high-throughput app like FastAPI.

Tech stack

Pythonasynciohiredis

Getting it running

Difficulty · easy Time to first run · 5min

Requires a running Redis server, the quickest way is docker run -p 6379:6379 redis.

In plain English

redis-py is the official Python library for working with Redis, a fast in-memory data store often used to cache information or pass messages between parts of an application. Redis itself runs as a separate server process that stores data in memory for very quick access. This library is what lets a Python program connect to that server and send it commands. Using the library is straightforward: you import it, create a connection object pointing at your Redis server, and then call methods on that connection to store and retrieve values. For example, you can store the string "bar" under the key "foo" with one line of code, and read it back with another. The library translates those method calls into the network protocol that Redis understands. Beyond basic key-value storage, Redis supports many data structures such as lists, sets, hashes, and sorted sets, and the library exposes all of them. It also supports running multiple commands at once in a pipeline to reduce round trips to the server, subscribing to message channels (pub/sub), and working with Redis clusters that span multiple machines. For Python programs that need to handle many simultaneous operations without waiting, the library includes an async version that works with Python's asyncio system. There is also an optional compiled component called hiredis that speeds up parsing responses from Redis. Installation is a single pip command, and full documentation with examples is available on the project's documentation site.

Copy-paste prompts

Prompt 1
Show me how to connect redis-py to a local Redis server, store a value with a 10-minute expiry, and retrieve it, with full working Python code.
Prompt 2
Using redis-py, implement a simple pub/sub system where one Python script publishes messages to a channel and another subscribes and prints each message as it arrives.
Prompt 3
How do I use redis-py's async client with Python asyncio in a FastAPI app to handle many Redis reads and writes concurrently without blocking?
Prompt 4
Show me how to use a redis-py pipeline to batch 100 SET commands into a single round trip and then retrieve all the values back with another pipeline.
Open on GitHub → Explain another repo

← redis on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.