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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.473s · 23.6MB
glibcpy 3.10–3.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()
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.
fixEnsure 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.
fixUpgrade 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.
fixUse '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.
fixEnsure 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.
fixUpdate 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].