Install & Compatibility
Where this runs
tested against v1.1.1 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 22.6MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.9s · import 0.000s · 23MB
21MB installed
● package 21MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
RedisConnection
✓ from pyredis import RedisConnection
✗ from pyredis import get_redis_client
wrapper
✓ from pyredis import wrapper
This quickstart demonstrates how to get a Redis client using `get_redis_client`, leveraging environment variables for configuration. It then performs a basic `set` and `get` operation, ensuring `decode_responses=True` for string handling.
import os
from pyredis import get_redis_client
# Configure Redis connection via environment variables for robustness
# Example: REDIS_HOST=localhost REDIS_PORT=6379 REDIS_DB=0 REDIS_PASSWORD=""
# Fallback to defaults if env vars are not set
redis_host = os.environ.get('REDIS_HOST', 'localhost')
redis_port = int(os.environ.get('REDIS_PORT', '6379'))
redis_db = int(os.environ.get('REDIS_DB', '0'))
redis_password = os.environ.get('REDIS_PASSWORD') or None
try:
# Get a configured Redis client instance
# decode_responses=True is highly recommended for working with strings
redis_client = get_redis_client(
host=redis_host,
port=redis_port,
db=redis_db,
password=redis_password,
decode_responses=True
)
# Test the connection
redis_client.ping()
print("Successfully connected to Redis!")
# Perform a simple operation
redis_client.set('mykey', 'Hello, py-redis!')
value = redis_client.get('mykey')
print(f"Retrieved from Redis: {value}")
redis_client.delete('mykey') # Clean up
except Exception as e:
print(f"Could not connect to Redis or an error occurred: {e}")
print("Please ensure Redis server is running and connection details are correct.")
Debug
Known issues
gotchaParameters passed directly to `get_redis_client()` will override any corresponding environment variables (e.g., `REDIS_HOST`, `REDIS_PORT`). Ensure your explicit arguments align with or intentionally override your environment setup.fixExplicitly check both environment variables and `get_redis_client` call arguments to understand the final configuration applied.
affects: All versions
gotchaBy default, `redis-py` (and thus `py-redis` if `decode_responses` is not set) returns byte strings. If you omit `decode_responses=True`, you'll receive bytes, which can lead to `TypeError` when expecting strings (e.g., in JSON serialization).fixAlways explicitly set `decode_responses=True` in `get_redis_client()` if you expect Python strings, or manually decode the byte strings using `.decode('utf-8')` after retrieval. affects: All versions
gotchaAs `py-redis` is a thin wrapper around `redis-py`, breaking changes or deprecations in the underlying `redis-py` library (which `py-redis` depends on) can indirectly affect your application, especially if `redis-py` itself is updated.fixRefer to `redis-py`'s changelog for major version updates. Ensure your `redis-py` dependency (either explicit or through `py-redis`'s requirements) is stable and compatible with your `py-redis` version.
affects: Any version where `redis-py` has major updates
Upgrade
Version history
1.1.1latest on PyPI · released Dec 13, 2021
Audit
Dependencies
redisrequiredRequired as `py-redis` wraps the official `redis-py` client library.