Common Redis Interview Questions and Answers
This article provides a comprehensive list of typical Redis interview questions covering its features, performance, data structures, supported data types, common use cases, eviction policies, persistence methods, clustering, high‑availability mechanisms, transaction handling, and comparisons with local caches like Guava and Caffeine.
Redis Features
High performance (read ~100,000 ops/s, write ~80,000 ops/s), data persistence (RDB, AOF), transaction support via MULTI and EXEC, multiple data structures, master‑slave replication, and additional capabilities such as pub/sub, notifications, and key expiration.
Why is Redis so fast?
In‑memory operation with minimal disk I/O (except asynchronous persistence).
Single‑threaded execution avoids context‑switch overhead.
Non‑blocking I/O multiplexing.
Optimized underlying data storage structures.
Underlying Data Structures
String (SDS dynamic string).
Linked list (doubly linked).
Hash table (dictionary).
Skiplist (used for sorted sets).
Intset (integer set).
Ziplist (compressed list).
Supported Data Types
Common types: String, Hash, Set, List, SortedSet. Special types: Bitmap, HyperLogLog, Geospatial.
Implementation details: String objects: int, embstr, raw. List objects: ziplist, linkedlist. Hash objects: ziplist, hashtable. Set objects: intset, hashtable. Zset objects: ziplist, skiplist.
Typical Use Cases
Cache (e.g., performance boost).
Distributed lock (using SETNX).
Distributed session storage.
Counters (INCR).
Leaderboards (sorted sets).
Seven Classic Cache Problems
Cache stampede.
Cache penetration.
Cache avalanche.
Cache hotspot.
Large cache keys.
Cache consistency.
Concurrent warm‑up.
Redis Cluster Options
Master‑slave replication.
Sentinel mode.
Redis Cluster mode.
Master‑Slave Replication Process
Slave sends SYNC to master.
Master performs BGSAVE to create RDB snapshot.
Master records slave’s write commands.
After BGSAVE, master sends RDB to slave.
Master streams buffered write commands to slave.
Subsequent writes are replicated in real time.
Sentinel Advantages & Disadvantages
Advantages: inherits master‑slave benefits, automatic failover.
Disadvantages: limited by single‑node capacity, requires extra sentinel processes.
Redis Cluster Advantages & Disadvantages
Advantages: no single point of failure, data sharded across 16384 slots, linear scalability, automatic failover via gossip protocol.
Disadvantages: asynchronous replication (no strong consistency), slaves are cold standby, limited multi‑key operations, only one DB (db0) per cluster.
Scaling and Slot Mechanism
Dynamic scaling uses consistent hashing; in Cluster mode, keys are mapped to slots via CRC16 modulo 16384, and only the relevant slots are migrated during scaling.
High Availability
Implemented via Sentinel, which monitors masters and slaves, promotes a slave to master upon failure, and notifies clients.
Transactions
Redis transactions group commands with MULTI/EXEC (or WATCH for optimistic locking). Commands are queued after MULTI, executed atomically on EXEC, or discarded with DISCARD. WATCH aborts EXEC if watched keys change.
WATCH monitors a key before MULTI; if the key is modified by another client, EXEC will abort.
Redis vs. Local Caches (Guava, Caffeine)
Local caches: in‑process memory, ultra‑fast, limited by process memory, no network overhead, data lost on restart.
Redis: distributed, supports large data sets, ensures consistency across nodes, higher latency than local cache but acceptable within a data center, provides replication for high availability.
Distributed Lock Implementations
Database table (poor performance).
Lua script combining SETNX + EXPIRE.
Extended SET command with NX/XX options.
Redlock algorithm.
Zookeeper Curator framework.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
