Databases 23 min read

40 Essential Redis Interview Questions Every Candidate Should Know

This article compiles 40 common Redis interview questions covering fundamentals, data types, persistence, clustering, performance tuning, memory optimization, and practical usage patterns, providing concise answers that help candidates confidently tackle Redis topics and secure job offers during the competitive hiring season.

ITFLY8 Architecture Home
ITFLY8 Architecture Home
ITFLY8 Architecture Home
40 Essential Redis Interview Questions Every Candidate Should Know

1. What is Redis?

Redis is a fully open‑source, BSD‑licensed high‑performance key‑value database.

Compared with other key‑value cache products, Redis has three main features:

Persistence – data can be saved to disk and reloaded on restart.

Supports richer data structures such as list, set, sorted set, hash.

Supports master‑slave replication for data backup.

Advantages:

Very high performance: read ~110 000 ops/s, write ~81 000 ops/s.

Rich data types: strings, lists, hashes, sets, ordered sets.

All operations are atomic; transactions are supported via MULTI/EXEC.

Additional features: publish/subscribe, notifications, key expiration, etc.

2. Redis data types

Redis supports five basic types: string, hash, list, set, and sorted set (zset). In practice, strings and hashes are most used; advanced users may also use HyperLogLog, Geo, Pub/Sub, and modules such as BloomFilter, RedisSearch, Redis‑ML.

3. Benefits of using Redis

Speed – data resides in memory, giving O(1) lookup similar to a HashMap.

Rich data structures – strings, lists, sets, zsets, hashes.

Transactional support – operations are atomic.

Multiple features – can be used for caching, messaging, key expiration, etc.

4. Redis vs. Memcached

Memcached stores only simple strings; Redis offers richer data types.

Redis is faster.

Redis provides persistence.

5. Differences between Memcached and Redis

Memcached keeps all data in memory and loses it on power‑off; Redis can persist to disk.

Redis supports complex data types; Memcached only simple strings.

Implementation differs – Redis uses its own VM, Memcached relies on system calls.

6. Is Redis single‑threaded?

Yes. Redis uses a single process and single thread, turning concurrent requests into serialized operations via an internal queue.

7. Maximum size of a string value

512 MB.

8. Persistence mechanisms

Redis offers RDB (snapshot) and AOF (append‑only file).

RDB

Creates a point‑in‑time snapshot saved to a temporary file, then replaces the previous snapshot.

Advantages: single file, easy backup, fast recovery using forked child process, better startup performance for large datasets.

Disadvantage: data may be lost between snapshots.

AOF

Logs every write command in the Redis protocol format.

Advantages: higher data safety (can configure always‑fsync), can be rewritten to shrink size, can recover from crashes with redis‑check‑aof.

Disadvantages: larger file, slower startup, slower with large datasets.

9. Common performance problems and solutions

Avoid RDB snapshots on the master during heavy load.

Enable AOF on a slave for important data, syncing every second.

Place master and slaves in the same LAN for low latency.

Do not add many slaves to a heavily loaded master.

Prefer a linear chain of replication (master←slave1←slave2…) for easier failover.

10. Expiration deletion strategies

Timed deletion – a timer removes the key exactly when it expires.

Lazy deletion – keys are checked for expiration on access.

Periodic deletion – Redis scans databases at intervals and removes expired keys.

11. Eviction policies

volatile‑lru – LRU among keys with an expiration.

volatile‑ttl – evicts keys that are about to expire.

volatile‑random – random eviction among expiring keys.

allkeys‑lru – LRU among all keys.

allkeys‑random – random eviction among all keys.

no‑eviction – disables eviction.

Choose based on data access patterns: LRU for power‑law distribution, random for uniform access.

12. Why does Redis keep data in memory?

In‑memory storage provides the fastest read/write speed; data is asynchronously persisted to disk. If maxmemory is set, new writes are rejected or old data is evicted.

13. Replication mechanism

Redis uses master‑slave replication. The master performs a BGSAVE, streams the RDB to the replica, then replays buffered commands.

14. Benefits of pipelining

Pipelining batches multiple commands into a single network round‑trip, greatly increasing QPS when commands are independent.

15. Redis Cluster vs. Sentinel

Sentinel provides high availability by promoting a slave when the master fails.

Cluster provides horizontal scalability by sharding data across multiple nodes.

16. Scenarios that make a Redis Cluster unavailable

If a node responsible for a slot range fails and there is no replica for that slot, the cluster becomes unavailable.

17. Java clients

Redisson, Jedis, Lettuce, etc. The official recommendation is Redisson.

18. Jedis vs. Redisson

Jedis offers a complete Redis command API. Redisson provides distributed Java data structures but lacks some low‑level features such as raw string commands, transactions, pipelines.

19. Setting and authenticating a password

Set password: CONFIG SET requirepass 123456 Authenticate:

AUTH 123456

20. Hash slots in Redis Cluster

Cluster uses 16 384 hash slots; each key’s CRC16 modulo 16384 determines its slot. Nodes own subsets of slots.

21. Cluster master‑slave model

Each master has N‑1 replicas to maintain availability when some nodes fail.

22. Can writes be lost in a cluster?

Redis does not guarantee strong consistency; under certain conditions writes may be lost.

23. Cluster replication

Replication is asynchronous.

24. Maximum number of nodes

16384 nodes (slots).

25. Database selection in a cluster

Cluster operates only on database 0; other databases are not supported.

26. Testing connectivity

Use the PING command.

27. Understanding transactions

Transactions are isolated and atomic; commands are executed sequentially without interleaving from other clients.

28. Transaction commands

MULTI, EXEC, DISCARD, WATCH.

29. Setting expiration vs. persisting keys

Use EXPIRE to set TTL and PERSIST to remove expiration.

30. Memory optimisation

Prefer hashes to store many small fields together, reducing overhead.

31. Memory reclamation process

When memory usage exceeds maxmemory, Redis applies the configured eviction policy.

32. Reducing memory usage

On 32‑bit instances, pack many small keys into hashes, lists, or sorted sets.

33. What happens when memory is exhausted?

Writes return an error; reads continue. With eviction enabled, old data is removed.

34. Limits on keys and collection sizes

Redis can handle up to 2³² keys; lists, sets, and sorted sets can each hold up to 2³² elements, limited only by available memory.

35. Keeping only hot data from MySQL in Redis

When the memory limit is reached, Redis evicts data according to the selected policy.

36. Typical use cases

Session cache – persistent, fast access.

Full‑page cache (FPC) – improves page load speed.

Message queues – using LIST or PUB/SUB.

Leaderboards / counters – using INCR and ZSET.

37. Finding keys with a common prefix

Use KEYS prefix*, but on a production server this blocks the single thread. Prefer SCAN to iterate without blocking, handling possible duplicates on the client side.

38. Setting many keys to expire at the same time

Avoid concentrating expirations; add a random offset to spread the load.

39. Using Redis as an asynchronous queue

Use a LIST: RPUSH to enqueue, LPOP or BLPOP to dequeue. For fan‑out, use PUB/SUB.

40. Distributed lock

Acquire with SETNX then set an expiration. Modern Redis supports SET key value NX EX seconds to combine both atomically.

Redis interview illustration
Redis interview illustration
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performancedatabaserediscachinginterview
ITFLY8 Architecture Home
Written by

ITFLY8 Architecture Home

ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.