gitmyhub

redis-py

Python ★ 14k updated 1d ago

Redis Python client

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.

Pythonasynciohiredissetup: easycomplexity 2/5

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.

Where it fits