Skip to content

python.redis.unbounded_keys

Stability High

Detects Redis key patterns that can grow unboundedly.

Unbounded Redis keys:

  • Memory exhaustion — Redis runs out of memory
  • Performance degradation — Large datasets slow operations
  • Service crash — OOM kills Redis process
# ❌ Before (unbounded keys)
def track_user_activity(user_id: str, action: str):
key = f"user:{user_id}:actions"
redis.lpush(key, action) # Grows forever!
# ✅ After (bounded with max length)
MAX_ACTIONS = 1000
def track_user_activity(user_id: str, action: str):
key = f"user:{user_id}:actions"
pipe = redis.pipeline()
pipe.lpush(key, action)
pipe.ltrim(key, 0, MAX_ACTIONS - 1) # Keep last 1000
pipe.execute()
  • LPUSH/RPUSH without LTRIM
  • SET accumulating without expiry
  • Unbounded ZADD operations