← ClaudeAtlas

redis-cache-testslisted

Use when Redis is the app's cache and its behavior needs tests, or when choosing a cache invalidation strategy: TTLs, cache-aside write and invalidate, eviction under memory pressure, pub/sub invalidation across nodes and tenant key namespaces, plus stampede and stale-while-revalidate patterns.
testland/qa · ★ 13 · Testing & QA · score 80
Install: claude install-skill testland/qa
# redis-cache-tests ## Overview Redis is the dominant application-tier cache. Per [redis.io/docs/latest/commands/expire/](https://redis.io/docs/latest/commands/expire/), keys get TTLs via `EXPIRE`, `PEXPIRE`, or `EXPIREAT` - with Redis 7+ flags `NX` / `XX` / `GT` / `LT` controlling conditional expiry. This skill wraps test patterns against a real Redis instance (via testcontainers or a dedicated test cluster) - **not** a mock. Mocks lose the eviction-policy + TTL-tick + pub-sub behaviours that real bugs hide in. ## When to use - Tests for code that uses Redis as a cache. - Verifying eviction policy under memory pressure. - Tenant-namespace tests for cache-key isolation. - Stampede-mitigation tests per [references/stampede.md](references/stampede.md). ## Authoring ### Install ```bash pip install redis testcontainers # Python npm install --save-dev ioredis testcontainers # Node ``` ### Real-Redis test fixture (Python) ```python import pytest import redis from testcontainers.redis import RedisContainer @pytest.fixture(scope="session") def redis_url(): with RedisContainer("redis:7-alpine") as r: yield r.get_connection_url() @pytest.fixture def r(redis_url): client = redis.from_url(redis_url, decode_responses=True) yield client client.flushdb() # Reset between tests ``` ### Basic TTL tests Per [redis.io](https://redis.io/docs/latest/commands/expire/): ```python def test_expire_sets_ttl(r): r.set("k", "v") assert r.expire("