Registry / database / redis
library8.1.0pypypi✓ verified 28d ago

Official Python client for Redis. Install is 'redis', import is 'redis'. Current version: 7.4.0 (Mar 2026). aioredis was merged into redis-py 4.2+ — use 'redis.asyncio' for async, not separate aioredis package. By default all responses are bytes — set decode_responses=True for strings. StrictRedis renamed to Redis in v3 but alias still works.

pip install redis
INSTALL
IMPORT
SIG · REDIS
R
redis
databasepythonv8.1.0
Install
2.2s avg
Import
439ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.473s · 23.6MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.2s · import 0.405s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Redis (sync)
import redis r = redis.Redis( host='localhost', port=6379, db=0, decode_responses=True # returns str not bytes ) r.set('key', 'value') print(r.get('key')) # 'value' not b'value'
import redis r = redis.Redis(host='localhost') print(r.get('key')) # returns b'value' — bytes not str
decode_responses defaults to False. Without it get() returns bytes (b'value') not str ('value'). This silently breaks string comparisons throughout your code.
redis.asyncio (async)
import redis.asyncio as aioredis import asyncio async def main(): r = aioredis.Redis( host='localhost', port=6379, decode_responses=True ) await r.set('key', 'value') print(await r.get('key')) await r.aclose() asyncio.run(main())
import aioredis # separate package — abandoned r = await aioredis.create_redis_pool('redis://localhost')
aioredis separate package is abandoned. Use 'import redis.asyncio as aioredis' from redis >= 4.2. aioredis PyPI package last release 2021.
from_url
import redis # Standard Redis URL r = redis.from_url('redis://localhost:6379/0', decode_responses=True) # Redis with password r = redis.from_url('redis://:password@localhost:6379/0') # SSL/TLS (Upstash, Redis Cloud) r = redis.from_url('rediss://user:pass@host:6380/0')
import redis r = redis.from_url('redis://localhost') # missing decode_responses
SSL connections use 'rediss://' (double s) not 'redis://'. from_url also defaults to decode_responses=False.

Minimal redis-py 7.x sync operations with decode_responses.

# pip install redis import redis r = redis.Redis( host='localhost', port=6379, db=0, decode_responses=True # str not bytes ) # Basic operations r.set('name', 'Alice') print(r.get('name')) # 'Alice' # Expiry r.setex('session', 3600, 'token123') # TTL 1 hour # Hash r.hset('user:1', mapping={'name': 'Alice', 'age': '30'}) print(r.hgetall('user:1')) # {'name': 'Alice', 'age': '30'} # List r.lpush('queue', 'task1', 'task2') print(r.lrange('queue', 0, -1)) r.close()
Debug
Known issues
gotchadecode_responses defaults to False. All values returned as bytes (b'value') not strings. Silently breaks string comparisons, JSON parsing, and any code expecting str.
fix
Always pass decode_responses=True unless you specifically need bytes: Redis(host='localhost', decode_responses=True)
affects: all
breakingaioredis separate package is abandoned (last release 2021). 'import aioredis' still installs but is dead. Use 'import redis.asyncio as aioredis' from redis >= 4.2.
fix
Replace 'import aioredis' with 'import redis.asyncio as aioredis'. API is compatible.
affects: >= 4.2
gotchaSSL connections require 'rediss://' (double s) URL scheme, not 'redis://'. Using wrong scheme silently connects without TLS or raises ConnectionError.
fix
redis.from_url('rediss://host:6380') for TLS. 'redis://' is plaintext.
affects: all
gotchaUpstash Redis requires TLS — always use rediss:// with Upstash URLs. Using redis:// with Upstash raises ConnectionError.
fix
r = redis.from_url(os.environ['UPSTASH_REDIS_URL'], decode_responses=True) — Upstash provides rediss:// URLs automatically.
affects: all
gotchaStrictRedis renamed to Redis in v3. StrictRedis still works as an alias but generates confusion in docs. Use Redis directly.
fix
from redis import Redis not StrictRedis
affects: >= 3.0
gotchaConnection pool is shared by default. Do not call r.close() in web request handlers — it closes the pool. Use aclose() in async or let the pool manage connections.
fix
Create one Redis client at app startup and reuse it. Only close on app shutdown.
affects: all
gotchaZADD argument order changed in v3. Old: zadd(name, member, score). New: zadd(name, {member: score}). Old order raises TypeError silently or produces wrong results.
fix
r.zadd('leaderboard', {'player1': 100.0})
affects: >= 3.0
breakingConnection refused. This usually means the Redis server is not running or is not accessible at the specified host and port.
fix
Ensure the Redis server is running and accessible from where the client is executing. Check firewall rules, network configuration, and that the Redis server is listening on the expected host/port.
affects: all
breakingThe client failed to connect to the Redis server because the connection was refused. This typically means the Redis server is not running, is not listening on the specified host/port, or a firewall is blocking the connection.
fix
Ensure the Redis server is running and accessible at the specified host and port (default: localhost:6379). Check firewall rules if connecting remotely.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'redis.asyncio'
The 'redis.asyncio' module is not found, possibly due to an outdated 'redis' package or incorrect import.
fix
Ensure you have 'redis' version 4.2.0 or higher installed and import using 'import redis.asyncio as redis'.
AttributeError: module 'redis' has no attribute 'asyncio'
The 'redis' package version is below 4.2.0, which does not include the 'asyncio' module.
fix
Upgrade the 'redis' package to version 4.2.0 or higher using 'pip install --upgrade redis'.
AttributeError: module 'aioredis' has no attribute 'create_redis'
The 'create_redis' method was removed in 'aioredis' version 2.0.0.
fix
Use 'aioredis.from_url' instead of 'create_redis' to establish a connection.
AttributeError: 'Redis' object has no attribute 'pubsub'
The 'pubsub' method is not available in the 'Redis' object due to incorrect usage or version incompatibility.
fix
Ensure you are using the correct version of 'aioredis' and refer to the updated documentation for the correct usage of 'pubsub'.
AttributeError: module 'redis' has no attribute 'client'
The 'redis' package structure has changed, and the 'client' module is no longer directly accessible.
fix
Update your code to use 'from redis import Redis' instead of accessing 'redis.client' directly.
Upgrade
Version history
8.1.0latest on PyPI · released Jul 30, 2026
Audit
Dependencies
hiredisoptionalOptional C parser for better performance. Install via redis[hiredis].
Agent activity
55 hits · last 30 days
node
52
Resources
redis — pip install redis · libregistry