Top 100 Redis Interview Questions

An essential guide for backend developers and DevOps engineers. Covering data types, persistence, clustering, and more.

This guide provides a curated list of common Redis interview questions to help you prepare for your next backend or DevOps role. Master these concepts to demonstrate your expertise in in-memory data stores and caching.

Last Updated: Aug 30, 2025

Table of Contents

Core Concepts

1. What is Redis?

Redis (Remote Dictionary Server) is an open-source, in-memory data structure store, used as a database, cache, and message broker. It supports various data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, and geospatial indexes. You can learn more from the official Redis website.

2. What are the main advantages of Redis?

  • Performance: Being an in-memory database, Redis provides extremely fast read and write operations.
  • Rich Data Types: Supports versatile data structures beyond simple key-value pairs.
  • Persistence: Offers options to persist data to disk (RDB and AOF).
  • High Availability: Supports replication and Sentinel for automatic failover.
  • Scalability: Can be scaled horizontally using Redis Cluster.

3. What are the main disadvantages of Redis?

  • Memory Limitation: Being in-memory, it's limited by the amount of RAM available.
  • Persistence Overhead: Persistence mechanisms can impact performance.
  • Single-threaded: Redis uses a single thread for command processing, which can be a bottleneck for CPU-intensive operations.
  • Cost: High memory requirements can make it expensive for large datasets.

4. What is the difference between Redis and Memcached?

  • Data Types: Redis supports more complex data types (lists, sets, hashes, etc.) while Memcached only supports strings.
  • Persistence: Redis offers persistence options, while Memcached does not.
  • Replication: Redis supports master-slave replication, while Memcached does not.
  • Memory Management: Redis uses both LRU eviction and expiration, while Memcached uses LRU only.

5. What is the maximum key size and value size in Redis?

Redis keys can be up to 512MB in size, and values can also be up to 512MB. However, it's recommended to keep keys and values much smaller for optimal performance.

6. Is Redis single-threaded or multi-threaded?

Redis uses a single-threaded model for command execution, but uses multiple threads for background tasks like persistence and network I/O in newer versions (Redis 6+ introduced I/O threading). This design avoids context switching and synchronization issues, making Redis very fast for most use cases.

7. What programming languages can be used with Redis?

Redis has client libraries for几乎所有 major programming languages including Python, Java, JavaScript (Node.js), Ruby, PHP, Go, C#, C++, and many others. This makes it highly accessible across different technology stacks.

8. What is the default port that Redis runs on?

The default port for Redis is 6379. This number comes from the name of Italian actress Alessia Merz, which was spelled on a telephone keypad as "MERZ" (6379).

9. What are some common use cases for Redis?

  • Caching (to reduce database load)
  • Session storage
  • Message brokering (Pub/Sub)
  • Real-time analytics
  • Leaderboards and counting
  • Geospatial applications
  • Rate limiting

10. How does Redis achieve high performance?

  • In-memory data storage
  • Single-threaded architecture avoiding context switches
  • Non-blocking I/O with epoll/kqueue
  • Optimized data structures
  • Pipelining to reduce round-trip time

Data Types

11. What are the primary data types in Redis?

The primary data types are Strings, Lists, Sets, Sorted Sets, and Hashes. Redis also supports more advanced types like Bitmaps, HyperLogLogs, and Geospatial indexes.

12. What are Redis Strings and when would you use them?

Redis Strings are binary-safe sequences of bytes. They can store text, serialized objects, or binary data. Use Strings for caching HTML fragments, storing user sessions, counters, or any simple key-value data.

13. What are Redis Lists and when would you use them?

Redis Lists are collections of ordered strings. They support operations like pushing/popping from both ends. Use Lists for implementing queues, stacks, or activity feeds.

14. What are Redis Sets and when would you use them?

Redis Sets are unordered collections of unique strings. They support operations like union, intersection, and difference. Use Sets for tracking unique items, tags, or implementing voting systems.

15. What are Redis Sorted Sets and when would you use them?

Redis Sorted Sets are similar to Sets but each member has an associated score used for ordering. Use Sorted Sets for leaderboards, priority queues, or time-series data.

16. What are Redis Hashes and when would you use them?

Redis Hashes are maps between string fields and string values. Use Hashes for representing objects (like users with multiple attributes) or storing multiple related fields together.

17. What are Redis Bitmaps and when would you use them?

Redis Bitmaps are not a separate data type but are built on the String type. They allow bit-level operations. Use Bitmaps for real-time analytics, feature flags, or efficient boolean arrays.

18. What are Redis HyperLogLogs and when would you use them?

HyperLogLogs are a probabilistic data structure used to estimate the cardinality (number of unique elements) of a set with a very small memory footprint. Use them for counting unique visitors, distinct events, etc., where approximate counts are acceptable.

19. What are Redis Streams and when would you use them?

Redis Streams are append-only logs that model a log data structure. They're ideal for event sourcing, message brokering, and time-series data where order matters.

20. What are Redis Geospatial indexes and when would you use them?

Redis Geospatial indexes allow storing and querying geographic coordinates. Use them for location-based features like finding nearby points of interest, calculating distances, or geofencing.

Commands & Operations

21. What is the Redis command to set a key-value pair?

The SET key value command is used to set a key to hold a string value. For example: SET user:1001 "John Doe"

22. What is the Redis command to get a value by key?

The GET key command is used to retrieve the value of a key. For example: GET user:1001 would return "John Doe".

23. How do you set a key with an expiration time in Redis?

You can use either:

  • SET key value EX seconds - Set with expiration in seconds
  • SET key value PX milliseconds - Set with expiration in milliseconds
  • Or use EXPIRE key seconds after setting the key

24. What is the difference between DEL and UNLINK commands?

DEL synchronously removes the key and returns the number of keys removed. UNLINK is non-blocking - it only unlinks the keys from the keyspace, and the actual memory reclamation happens later in a different thread.

25. What is the SCAN command and why is it better than KEYS?

SCAN is a cursor-based iterator that allows incrementally iterating over the keyspace without blocking the server. KEYS pattern command blocks the server until it completes, which can be problematic for large databases.

26. How do you atomically increment a value in Redis?

Use the INCR key command to atomically increment the integer value of a key by 1. For incrementing by a specific amount, use INCRBY key increment.

27. What is the difference between LPUSH and RPUSH?

LPUSH inserts values at the head (left) of a list, while RPUSH inserts values at the tail (right) of a list.

28. How do you add members to a Set in Redis?

Use the SADD key member [member ...] command to add one or more members to a set. For example: SADD tags redis database nosql

29. How do you add members to a Sorted Set in Redis?

Use the ZADD key score member [score member ...] command to add one or more members to a sorted set, each with a specified score. For example: ZADD leaderboard 100 "player1" 200 "player2"

30. How do you store multiple field-value pairs in a Hash?

Use the HSET key field value [field value ...] command to set multiple field-value pairs in a hash. For example: HSET user:1001 name "John" age 30 email "john@example.com"

Persistence (RDB & AOF)

31. What is Redis persistence?

Redis persistence refers to the mechanisms Redis uses to write data to disk so that it can survive restarts. The two main persistence options are RDB (snapshotting) and AOF (append-only file).

32. What is RDB persistence?

RDB (Redis Database) persistence performs point-in-time snapshots of your dataset at specified intervals. It creates a compact binary file representing the entire dataset at that moment.

33. What is AOF persistence?

AOF (Append Only File) persistence logs every write operation received by the server. These operations can then be replayed again at server startup, reconstructing the original dataset.

34. What are the advantages of RDB?

  • Compact single file representation of data
  • Faster restarts compared to AOF with large datasets
  • Maximal durability for a given dataset size
  • Allows backups and disaster recovery

35. What are the advantages of AOF?

  • More durable (can be configured to fsync every write)
  • Append-only log makes it less prone to corruption
  • Log is human-readable (in Redis protocol format)
  • Easier to understand what's happening with the data

36. What are the disadvantages of RDB?

  • Risk of data loss if Redis stops working between snapshots
  • Can be resource-intensive for large datasets (saving requires forking)

37. What are the disadvantages of AOF?

  • AOF files are usually larger than equivalent RDB files
  • Can be slower than RDB depending on fsync policy
  • Redis restarts can be slower with large AOF files

38. Can you use both RDB and AOF together?

Yes, you can enable both RDB and AOF persistence. In this case, when Redis restarts, the AOF file will be used to reconstruct the original dataset since it is guaranteed to be the most complete.

39. What is the AOF rewrite process?

AOF rewrite creates a compact version of the AOF file by reading the current dataset and writing the minimal sequence of commands needed to reconstruct it. This prevents the AOF from growing indefinitely.

40. What are the different AOF fsync policies?

  • no: Never fsync, let the OS flush data (fastest, least safe)
  • everysec: Fsync every second (good balance between speed and safety)
  • always: Fsync after every write (slowest, safest)

Replication & Sentinel

41. What is Redis replication?

Redis replication allows a Redis server (slave/replica) to exactly copy the data of another Redis server (master). This provides read scalability and data redundancy.

42. How does Redis replication work?

When a replica connects to a master:

  1. It sends a SYNC command
  2. The master starts background saving and buffers all new commands
  3. After saving, the master sends the RDB file to the replica
  4. The replica loads the RDB file
  5. The master sends buffered commands to the replica

43. What is Redis Sentinel?

Redis Sentinel is a distributed system that provides high availability for Redis. It monitors Redis instances, notifies administrators of issues, and automatically handles failover when a master is not working properly.

44. What are the main functions of Redis Sentinel?

  • Monitoring: Checking if master and replica instances are working properly
  • Notification: Alerting administrators when something is wrong
  • Automatic failover: Promoting a replica to master if the current master fails
  • Configuration provider: Acting as a source of authority for clients

45. What is the difference between replication and sharding?

Replication involves copying data across multiple nodes for redundancy and read scalability. Sharding involves partitioning data across multiple nodes to distribute load and storage capacity.

46. What is partial resynchronization in Redis replication?

Partial resynchronization (PSYNC) allows a replica to reconnect and continue replication from where it left off, using the replication backlog buffer, rather than requiring a full resync.

47. How many Sentinels are needed for a robust setup?

For a robust setup, it's recommended to have at least 3 Sentinel instances, deployed on different physical servers or virtual machines to avoid single points of failure.

48. What is the role of the replication backlog buffer?

The replication backlog buffer is a fixed-size buffer that accumulates data from the master. It's used for partial resynchronization when replicas reconnect after a disconnection.

49. Can replicas accept write operations?

By default, replicas are read-only and reject write operations. This can be changed with the replica-read-only configuration directive, but it's generally not recommended.

50. What happens during a Sentinel failover?

During a failover:

  1. Sentinels detect the master is down
  2. They vote for a leader Sentinel to handle the failover
  3. The leader selects the best replica to promote
  4. The selected replica is promoted to master
  5. Other replicas are reconfigured to replicate from the new master

Clustering

51. What is Redis Cluster?

Redis Cluster is a distributed implementation of Redis that automatically shards data across multiple Redis nodes, providing both high availability and scalability.

52. How does Redis Cluster shard data?

Redis Cluster uses hash slots (16384 slots total) to shard data. Each key is assigned to a slot using a CRC16 hash function modulo 16384. Each node in the cluster is responsible for a subset of these hash slots.

53. What is the minimum number of nodes required for a Redis Cluster?

The minimum number of nodes for a functional Redis Cluster is 3 master nodes. For high availability, you should have at least 3 master nodes and 3 replica nodes (6 nodes total).

54. How does Redis Cluster handle node failure?

When a master node fails, one of its replicas is promoted to master. If a master node has no replicas and fails, the cluster becomes unavailable for the portion of hash slots that master was responsible for.

55. What is the role of gossip protocol in Redis Cluster?

The gossip protocol is used by Redis Cluster nodes to discover other nodes, detect failures, publish important cluster information, and promote replica nodes when needed.

56. How does Redis Cluster handle requests for keys not on the current node?

When a client requests a key that isn't on the connected node, the node responds with a MOVED redirect that tells the client which node is responsible for that key's hash slot.

57. What is the difference between MOVED and ASK redirects?

A MOVED redirect indicates that the hash slot has been permanently moved to another node. An ASK redirect is a temporary redirect that occurs during resharding when a key might be in transition between nodes.

58. What are the limitations of Redis Cluster?

  • Does not support multi-key operations across different nodes (unless all keys hash to the same slot)
  • Database selection (SELECT command) is not supported (only database 0)
  • No nested transaction support

59. How do you add a new node to a Redis Cluster?

You can add a new node using the CLUSTER MEET command to introduce it to the cluster, then use CLUSTER ADDSLOTS to assign hash slots to it (if it's a master) or configure it as a replica of an existing master.

60. What is the process of resharding in Redis Cluster?

Resharding involves moving hash slots from one node to another. This is done using the CLUSTER SETSLOT command with the IMPORTING and MIGRATING options, followed by migrating the actual keys using the MIGRATE command.

Transactions & Pipelining

61. What are Redis transactions?

Redis transactions allow executing a group of commands as a single atomic operation. Commands in a transaction are serialized and executed sequentially without interruption by other clients.

62. How do you execute a transaction in Redis?

Transactions are executed using the MULTI, EXEC commands:

  1. MULTI starts a transaction
  2. Queue commands with standard Redis commands
  3. EXEC executes all queued commands

63. Are Redis transactions atomic?

Yes, Redis transactions are atomic, meaning either all commands are processed or none are. However, unlike SQL databases, Redis transactions don't have rollback capability - if a command fails during execution, the others will still be processed.

64. What is the difference between WATCH and MULTI/EXEC?

WATCH is used for optimistic locking. It monitors keys for changes before a transaction. If any watched key is modified before EXEC, the entire transaction is aborted. MULTI/EXEC groups commands without checking for changes.

65. What is pipelining in Redis?

Pipelining is a technique where a client sends multiple commands to the server without waiting for each response, and then reads all responses at once. This reduces the round-trip time and significantly improves performance.

66. What are the benefits of pipelining?

  • Dramatically improved performance for multiple operations
  • Reduced network latency by batching commands
  • More efficient use of network resources

67. What is the difference between transactions and pipelining?

Transactions guarantee atomicity (all commands execute or none do) and isolate the execution from other clients. Pipelining is just a network optimization technique that batches commands but doesn't provide atomicity guarantees.

68. What is the DISCARD command used for?

The DISCARD command flushes all previously queued commands in a transaction and restores the connection to normal state. It's used to abort a transaction without executing it.

69. Can you use WATCH without MULTI/EXEC?

No, WATCH is designed to work with transactions. It monitors keys for changes, and if changes are detected when EXEC is called, the transaction is aborted.

70. What happens if a Redis command fails during a transaction?

Redis transactions continue executing commands even if some fail. There's no rollback mechanism. The client receives the results of each command in the transaction, including any errors.

Pub/Sub & Streams

71. What is Redis Pub/Sub?

Redis Pub/Sub (Publish/Subscribe) is a messaging pattern where senders (publishers) send messages to channels without knowing who will receive them, and receivers (subscribers) express interest in channels without knowing who will send messages.

72. How does Redis Pub/Sub work?

Clients can subscribe to channels using SUBSCRIBE and publish messages to channels using PUBLISH. When a message is published to a channel, all subscribed clients receive the message.

73. What is pattern matching in Redis Pub/Sub?

Redis supports pattern matching with the PSUBSCRIBE command, which allows clients to subscribe to channels matching a glob-style pattern (e.g., news.*).

74. What are the limitations of Redis Pub/Sub?

  • Messages are not persisted - if a subscriber is disconnected, it misses messages
  • No acknowledgment mechanism
  • No message replay capability
  • No guarantee of message delivery

75. What are Redis Streams?

Redis Streams is a log data structure introduced in Redis 5.0 that models a log where each entry has a unique ID and contains field-value pairs. It addresses limitations of Pub/Sub by providing persistence and consumer groups.

76. What are consumer groups in Redis Streams?

Consumer groups allow multiple consumers to cooperate on consuming messages from a stream. Each message is delivered to a single consumer within the group, enabling load balancing and competing consumer patterns.

77. How do Redis Streams differ from Pub/Sub?

  • Streams persist messages, Pub/Sub doesn't
  • Streams support consumer groups with load balancing
  • Streams allow reading historical messages
  • Streams provide acknowledgment mechanisms

78. What is the XADD command used for?

The XADD command appends a new entry to a stream. It requires the stream key, an ID (usually * for auto-generation), and field-value pairs. Example: XADD mystream * sensor-id 1234 temperature 19.8

79. What is the XREAD command used for?

The XREAD command reads entries from one or more streams. It can block waiting for new entries and read from a specific position. Example: XREAD COUNT 2 STREAMS mystream 0

80. How do you create a consumer group for a stream?

Use the XGROUP CREATE command: XGROUP CREATE mystream mygroup $ (where $ means start from the end of the stream, or 0 to start from the beginning).

Memory Management & Eviction

81. What happens when Redis runs out of memory?

When Redis runs out of memory, its behavior depends on the configured maxmemory-policy. It can either return errors for write commands or evict some keys according to the policy.

82. What are the Redis memory eviction policies?

  • noeviction: Returns errors when memory limit is reached
  • allkeys-lru: Evicts least recently used keys
  • volatile-lru: Evicts least recently used keys among those with expire set
  • allkeys-random: Randomly evicts keys
  • volatile-random: Randomly evicts keys with expire set
  • volatile-ttl: Evicts keys with shortest time to live

83. What is the difference between allkeys-* and volatile-* policies?

allkeys-* policies consider all keys for eviction, while volatile-* policies only consider keys with an expiration set.

84. How does Redis approximate LRU eviction?

Redis uses an approximated LRU algorithm that samples a small number of keys and evicts the one that was used least recently among the sampled keys. This is more efficient than a true LRU implementation.

85. What is memory fragmentation in Redis?

Memory fragmentation occurs when allocated memory becomes divided into small, non-contiguous blocks. This can happen due to how Redis allocates and frees memory for different data types and operations.

86. How can you reduce memory fragmentation in Redis?

  • Use appropriate data types for your use case
  • Use the activedefrag configuration option
  • Restart Redis periodically (if acceptable for your use case)
  • Use smaller values or compress values

87. What is the INFO memory command used for?

The INFO memory command provides detailed information about memory usage, including total memory used, memory fragmentation ratio, and various other memory-related metrics.

88. What is the memory overhead of Redis data structures?

Redis data structures have some memory overhead beyond the raw data. For example, each key has about 96 bytes of overhead, and each data structure (list, set, etc.) has additional metadata overhead.

89. How can you reduce memory usage in Redis?

  • Use appropriate data types (hashes instead of separate keys)
  • Use ziplist encoding for small lists, hashes, and sorted sets
  • Use integer encoding for numbers when possible
  • Shorten key names (but balance with readability)
  • Use Redis' built-in memory optimization features

90. What is the role of the maxmemory configuration directive?

The maxmemory directive sets the maximum amount of memory Redis can use. When this limit is reached, Redis will start evicting keys according to the configured maxmemory-policy.

Use Cases & Best Practices

91. What are some common Redis use cases?

  • Caching: Storing frequently accessed data to reduce database load
  • Session storage: Storing user session data
  • Leaderboards: Using sorted sets for real-time rankings
  • Message queues: Using lists or streams for job queues
  • Real-time analytics: Using HyperLogLog for unique counts
  • Rate limiting: Using counters with expiration

92. When should you not use Redis?

  • When you need complex querying capabilities (use a relational database)
  • When your dataset is too large for available memory
  • When you need strong ACID compliance
  • When you need to store large binary data
  • When data persistence is not critical (though Redis can be configured for persistence)

93. What are some Redis security best practices?

  • Use authentication (requirepass configuration)
  • Run Redis in a protected network environment
  • Use firewall rules to restrict access
  • Disable dangerous commands (FLUSHALL, CONFIG, etc.)
  • Use encrypted connections (SSL/TLS) for client communication

94. How can you monitor Redis performance?

  • Use the INFO command to get server statistics
  • Use the MONITOR command to see commands in real-time (use cautiously)
  • Use the SLOWLOG command to identify slow queries
  • Use Redis' built-in metrics and export them to monitoring systems

95. What is the Redis benchmarking tool and how is it used?

The redis-benchmark tool is used to measure the performance of a Redis instance. It can simulate multiple clients making requests to test throughput and latency. Example: redis-benchmark -q -n 100000

96. How do you backup Redis data?

  • Use RDB persistence and copy the RDB file
  • Use AOF persistence and copy the AOF file
  • Use the SAVE or BGSAVE commands to create snapshots
  • For replication setups, backup from a replica to avoid impacting the master

97. What is Lua scripting in Redis and why is it useful?

Redis supports execution of Lua scripts via the EVAL and SCRIPT commands. This is useful for implementing complex operations that need to be atomic, reducing network round-trips, and implementing custom functionality.

98. What are some common Redis performance tuning techniques?

  • Use pipelining to reduce round-trip times
  • Use appropriate data structures for your use case
  • Configure persistence appropriately for your durability needs
  • Use connection pooling in clients
  • Monitor and optimize memory usage

99. How do you handle failover and recovery in Redis?

  • Use Redis Sentinel for automatic failover
  • Use Redis Cluster for automatic sharding and failover
  • Have proper monitoring and alerting in place
  • Maintain regular backups
  • Test your failover procedures regularly

100. What are some common mistakes to avoid when using Redis?

  • Using long-running commands (like KEYS *) in production, which can block the server.
  • Not configuring memory eviction policies, leading to memory exhaustion.
  • Failing to set up proper persistence, risking data loss on restart.
  • Not using connection pooling in client applications.
  • Ignoring security best practices, such as running Redis on a public network without a password.
DevUtilityTool Logo

About the Author

This guide is curated by the team at DevUtilityTool, who are passionate about creating high-quality, accessible resources that help developers excel in their careers.