40 Common Redis Interview Questions and Answers
This article compiles 40 frequently asked Redis interview questions covering fundamentals, data types, persistence, clustering, performance tuning, memory optimization, security, and advanced usage such as pipelines and distributed locks, providing concise answers to help candidates prepare confidently for technical interviews.
To assist candidates preparing for Redis interviews, this guide presents 40 common questions and concise answers covering a wide range of topics.
1. What is Redis? Redis is an open‑source, BSD‑licensed, high‑performance key‑value database that supports persistence, multiple data structures (string, list, set, sorted set, hash), and master‑slave replication.
2. Data types Redis supports five primary types: string, hash, list, set, and sorted set. Advanced structures include HyperLogLog, Geo, and Pub/Sub.
3. Benefits High read/write speed (≈110 000 ops/s read, 81 000 ops/s write), rich data types, atomic operations (single commands are atomic; multi‑command transactions use MULTI and EXEC), and features like publish/subscribe and key expiration.
4. Redis vs. Memcached Redis offers richer data types, higher speed, and persistence, whereas Memcached only stores simple strings in memory.
5. Persistence mechanisms Redis provides RDB and AOF. RDB creates snapshots ( dump.rdb) offering fast startup but possible data loss between snapshots. AOF logs every command, ensuring higher durability but larger files and slower recovery.
6. Performance tuning Avoid heavy SAVE operations on the master, use AOF on slaves for safety, keep master and slaves in the same LAN, and prefer a linear replication chain (master ← slave1 ← slave2 …) for quick failover.
7. Expiration strategies Redis supports timed deletion, lazy deletion, and periodic deletion to manage expired keys.
8. Eviction policies Six policies: volatile-lru, volatile-ttl, volatile-random, allkeys-lru, allkeys-random, and no-eviction. Choose based on data access patterns.
9. Memory optimization Use hashes to pack related fields, prefer compact data structures, and on 32‑bit instances leverage lists, sets, and sorted sets efficiently.
10. Common use cases Session caching, full‑page caching, message queues (using list or pub/sub), leaderboards ( sorted set), and publish/subscribe for real‑time notifications.
11. Keys pattern search KEYS blocks the single‑threaded server; use SCAN for non‑blocking iteration.
12. Distributed lock Implement with SETNX followed by EXPIRE, or use the atomic SET key value NX EX seconds form.
13. Pipeline Reduces round‑trip latency by sending multiple commands in one batch when commands are independent.
14. Cluster and Sentinel Sentinel provides high availability by promoting a slave to master on failure; Cluster provides sharding across up to 16 384 hash slots.
15. Testing connectivity Use the PING command.
16. Transactions Commands are executed atomically using MULTI, EXEC, DISCARD, and WATCH. All commands in a transaction are either fully applied or not applied at all.
17. Setting and removing expiration Use EXPIRE to set TTL and PERSIST to make a key permanent.
18. Handling large numbers of keys Redis can theoretically store up to 2³² keys; practical limits depend on available memory.
19. Delayed queue Use a sorted set with timestamps as scores; consumers retrieve ready items with ZRANGEBYSCORE.
20. Common pitfalls Concentrated expiration times can cause short pauses; randomize TTLs to smooth load.
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.
IT Architects Alliance
Discussion and exchange on system, internet, large‑scale distributed, high‑availability, and high‑performance architectures, as well as big data, machine learning, AI, and architecture adjustments with internet technologies. Includes real‑world large‑scale architecture case studies. Open to architects who have ideas and enjoy sharing.
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.
