skillfed

python-redis-cache

Basic Redis caching for functions

python-redis-cache v4.0.2 200.8K downloads/30d#9,683 on PyPI115
Permissive license MIT AGING released

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-cache

uv

uv add python-redis-cache

poetry

poetry add python-redis-cache

Installing 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

redis function caching decoratorcache python functions with redisfunction result caching redisredis cache decoratormemoization with redisfunction memoization redisredis ttl cache
cachingredismemoization

More Database packages