Skip to content

1.16.0 — Redis Cache Adapter

Choose a tag to compare

@Cheater121 Cheater121 released this 04 Apr 16:41
· 10 commits to main since this release
6a87379

Adds a Redis-backed cache for distributed deployments:

  • New adapter: rbacx.core.redis_cache.RedisCache implementing AbstractCache
  • Designed for multi-process / multi-host setups where in-memory cache is not shared
  • Available via extra: rbacx[cache-redis]

Usage:

import redis
from rbacx import Guard
from rbacx.core.redis_cache import RedisCache

guard = Guard(
    policy,
    cache=RedisCache(redis.Redis(), prefix="rbacx:", default_ttl=300),
)

Key properties:

  • JSON serialization (no pickle)

  • TTL precedence: explicit ttldefault_ttl → no expiry

  • clear() uses SCAN with prefix glob (never FLUSHDB)

  • Redis errors are swallowed and logged at DEBUG level:

    • treated as cache miss
    • never impact authorization decisions
  • Compatible with:

    • redis.Redis
    • redis.cluster.RedisCluster
    • any compatible client interface

No breaking changes

Upgrade

pip install -U "rbacx[cache-redis]"