Redis interview questions

14 questions from the Redis Fundamentals: Caching, Data Structures and Persistence course, each with the correct answer and an explanation. Try to answer before you open the answer.

Module 1: Getting Started

1. What does a healthy Redis server reply to `PING`?

  1. OK
  2. ALIVE
  3. PONG
  4. ERROR
Show answer

Answer: PONG

`PING` is the standard liveness check and always returns `PONG`.

Lesson: redis-cli Basics

Module 2: Strings & Keys

2. Which command should you use to list keys in a production system?

  1. KEYS *
  2. GETALL
  3. FLUSHALL
  4. SCAN
Show answer

Answer: SCAN

`SCAN` iterates incrementally without blocking the server; `KEYS *` blocks until the whole keyspace is scanned.

Lesson: Working with Keys

Module 3: Data Structures

3. What keeps members in order inside a Redis sorted set?

  1. A numeric score attached to each member
  2. The order they were inserted
  3. Alphabetical order of the member name
  4. A random hash of the key
Show answer

Answer: A numeric score attached to each member

Sorted sets rank members by their score, updated any time with `ZADD` or `ZINCRBY`.

Lesson: Sorted Sets

Module 5: Caching Patterns

4. Which policy evicts the least recently used keys across the whole keyspace?

  1. noeviction
  2. allkeys-lru
  3. volatile-ttl
  4. allkeys-random
Show answer

Answer: allkeys-lru

allkeys-lru removes the least recently used keys when maxmemory is reached.

Lesson: Memory Limits & Eviction Policies

Module 6: Sessions

5. Why is Redis a good fit for sessions in a multi-server app?

  1. It stores sessions on disk permanently
  2. Every app server can read the same shared, fast session store
  3. It automatically logs every user out
  4. It makes sessions slower
Show answer

Answer: Every app server can read the same shared, fast session store

A shared, low-latency store means any server can serve any user's session without stickiness.

Lesson: Session Storage

Module 8: Beyond Basics

6. Does plain Redis Pub/Sub store messages for subscribers who are offline?

  1. Yes, forever
  2. Yes, but only for 24 hours
  3. No — only currently connected subscribers get it
  4. Only if AOF is disabled
Show answer

Answer: No — only currently connected subscribers get it

Pub/Sub has no storage — use Redis Streams when messages need to survive for offline consumers.

Lesson: Redis as a Message Broker

7. Which Redis data type is best for a live leaderboard?

  1. List
  2. String
  3. Sorted set
  4. Pub/Sub
Show answer

Answer: Sorted set

Sorted sets keep members ranked by score automatically.

Lesson: Redis as a Message Broker

8. Which command safely iterates keys on a production server?

  1. KEYS *
  2. FLUSHALL
  3. DEBUG
  4. SCAN
Show answer

Answer: SCAN

SCAN walks the keyspace in small non-blocking batches.

Lesson: Redis as a Message Broker

9. What does SET key value EX 60 do?

  1. Stores the value and expires it after 60 seconds
  2. Stores it for 60 days
  3. Appends 60 to the value
  4. Locks the key
Show answer

Answer: Stores the value and expires it after 60 seconds

EX sets the TTL in seconds together with the value.

Lesson: Redis as a Message Broker

10. In cache-aside, what happens on a cache miss?

  1. Redis queries the database itself
  2. The app reads the database and then fills the cache
  3. The request fails
  4. The cache is flushed
Show answer

Answer: The app reads the database and then fills the cache

The application owns loading data into the cache.

Lesson: Redis as a Message Broker

11. Which persistence option logs every write command?

  1. RDB
  2. Pub/Sub
  3. AOF
  4. Streams only
Show answer

Answer: AOF

AOF replays commands to rebuild the dataset with minimal loss.

Lesson: Redis as a Message Broker

12. Which maxmemory-policy suits a pure cache?

  1. noeviction
  2. volatile-ttl only
  3. none
  4. allkeys-lru
Show answer

Answer: allkeys-lru

Evicting least recently used keys keeps hot data in memory.

Lesson: Redis as a Message Broker

13. Why avoid exposing Redis directly to the internet?

  1. It was designed for trusted networks and can be hijacked
  2. It becomes slower
  3. It stops persisting
  4. It disables TTLs
Show answer

Answer: It was designed for trusted networks and can be hijacked

Bind to private interfaces, require auth and use a firewall.

Lesson: Redis as a Message Broker

14. Which Redis feature keeps a durable, replayable log of messages?

  1. Plain Pub/Sub
  2. Streams
  3. SCAN
  4. EXPIRE
Show answer

Answer: Streams

Streams (XADD/XREAD) retain messages for consumers that connect later.

Lesson: Redis as a Message Broker

← Back to the course