python-redis-cache
Basic Redis caching for functions
What it is and what it does
python-redis-cache wraps Python functions with a decorator that automatically caches their return values in Redis, keyed by function identity and arguments. When a decorated function is called with the same arguments again, the cached result is returned instead of re-executing the function body. It handles serialization of arguments and results (JSON by default), supports time-to-live (TTL) expiration, per-function namespaces, and Redis cluster mode via hash-tag key prefixes.
The package is designed for simple, declarative caching of expensive computations—database queries, API calls, heavy calculations—without modifying function logic. It provides methods to invalidate individual cached entries or clear all cached values for a function, and an optional exception handler to gracefully fall back to the original function if Redis is unavailable. The main constraint is that arguments and return values must be serializable; instance methods require refactoring to static methods or custom serializers to avoid serializing `self`.
Use it for:
- Cache expensive database queries or API responses to reduce latency on repeated calls with identical parameters.
- Memoize computationally intensive calculations across multiple function invocations to improve performance.
- Reduce load on external services by caching their responses with a configurable TTL before re-fetching.
- Implement a shared cache layer for multiple Python processes or services using a centralized Redis instance.
- Speed up test suites by caching slow fixture setup or mock data generation across test runs.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Decorator-based caching for Python functions using Redis as the backend store, with support for TTL, cache invalidation, and Redis cluster compatibility.
Yes, if you have Redis available and need straightforward function-level caching. The decorator pattern is intuitive and the package is stable with no known vulnerabilities. However, maintenance is aging (507 days since last release); consider it for established, low-change codebases rather than projects requiring active upstream support. Verify Python 3.6 compatibility claims if you target that version.
Install
python-redis-cache on PyPI
pip
pip install python-redis-cacheuv
uv add python-redis-cachepoetry
poetry add python-redis-cacheInstalling python-redis-cache
Before you install
Low friction install with a single runtime dependency on redis. Maintenance status is aging—last release was 507 days ago, though the repository remains active and not archived.
License in practice
MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute this package freely provided you include the license notice.
Quickstart
pip install python-redis-cache
from redis import StrictRedis
client = StrictRedis(host="redis", decode_responses=True)
# Create cache instance and decorate function
@cache.cache()
def my_func(arg1, arg2):
return expensive_operation()
my_func(1, 2) # Cached on second call
my_func.invalidate(1, 2) # Clear specific entry
my_func.invalidate_all() # Clear all entries
Requires Redis 5+ running and accessible; arguments and return values must be JSON-serializable by default (or use a custom serializer).
Verify before relying
- Whether Python 3.6 compatibility claim ('should work in Python 3.6+, but not tested') reflects actual tested support.
- Current stability and adoption rate given 507 days since last release and aging maintenance status.
- Performance characteristics and overhead of the decorator pattern in production workloads.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — redis |
| Maintenance | aging — 507 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 200,799/month — #9,683 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: python_redis_cache-4.0.2-py3-none-any.whl
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
asyncacheProvides decorator-based caching for async…
permissive · top 5,000 on PyPI
cachierCachier is a decorator that adds persistent,…
permissive · top 15,000 on PyPI
cashewsAsync cache framework with decorator and direct…
permissive · top 15,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
aiocacheProvides asyncio-compatible caching with…
unclear · top 5,000 on PyPI
async-lruAn LRU cache decorator for async functions that…
permissive · top 1,000 on PyPI
django-redisProvides a Redis cache and session backend for…
permissive · top 5,000 on PyPI
django-cacheopsAutomatic and manual ORM query caching for…
permissive · top 5,000 on PyPI
cachetools-asyncProvides async-aware memoization decorators for…
permissive · top 15,000 on PyPI
cachettlcachettl provides LRU TTL cache decorators for…
permissive · top 15,000 on PyPI