Redis Interview Questions
Redis Interview Questions Redis persistence options? RDB (snapshot): point-in-time snapshot, compact file, slower recovery but smaller. AOF (Append Only File): …
Redis Interview Questions
Redis persistence options? RDB (snapshot): point-in-time snapshot, compact file, slower recovery but smaller. AOF (Append Only File): logs every write, durable but larger. Use both for best durability. RDB for backups, AOF for fast recovery
What is Redis eviction policy? When memory full: noeviction (error), allkeys-lru (LRU across all), volatile-lru (LRU among TTL keys), allkeys-lfu (LFU), volatile-ttl (shortest TTL first). Set via maxmemory-policy in redis.conf
Implement distributed lock with Redis? SET key value NX PX 30000 — atomic, sets only if not exists, expires in 30s. Release: check value matches (your token) then DELETE atomically with Lua script. Redlock algorithm for multi-node safety
Why is Redis single-threaded? All commands execute in single thread — no locks needed, predictable latency, atomic by nature. Fast because all data in memory and single-threaded avoids context switching. I/O multiplexing for concurrency
Redis Cluster vs Sentinel? Sentinel: HA for single master — monitors, automatic failover to replica. Cluster: horizontal sharding — 16384 hash slots distributed across nodes, automatic rebalancing, built-in replication
Cache invalidation strategies? TTL expiry (simple, eventual consistency). Write-through: update cache on every write. Delete on write: invalidate cache key on update, repopulate on next read. Pub/sub: publish invalidation events to subscribers