yoklainterview sim

Database Redis Data Structures Interview Questions

75 verified Database Redis Data Structures interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Redis Data StructuresDifficulty 1
Which Redis data type is best suited for storing a simple counter, like a page view count?
  • aHash
  • bString
  • cSet
  • dList
Explanation:Redis strings can hold integers and support atomic INCR/INCRBY operations, making them the natural fit for counters. Hashes (a) are for multi-field objects, sets (c) for unique unordered collections, and lists (d) for ordered sequences — none offer atomic numeric increment directly on a single scalar value.
Redis Data StructuresDifficulty 1
RPUSH tasks "a" "b" "c"
LRANGE tasks 0 -1

What does LRANGE tasks 0 -1 return?
  • aOnly the first element, "a"
  • bOnly the last element, "c"
  • cAll elements: "a", "b", "c"
  • dAn error, because -1 is not a valid index
Explanation:LRANGE key start stop supports negative indexes, where -1 means the last element. 0 -1 therefore spans the entire list, returning all elements in order: "a", "b", "c". Negative indexes are a normal, documented feature (d is wrong), and the range is not limited to one end (a, b).
Redis Data StructuresDifficulty 2
You need to store a user profile (name, email, age) under a single Redis key and be able to update just the age field without rewriting the whole object. Which data type fits best?
  • aHash, with each profile field as a field-value pair inside it
  • bString, storing the whole profile as a JSON blob and rewriting it on every update
  • cList, appending a new profile version every time a field changes
  • dSet, with each field-value pair as a set member
Explanation:A hash maps field names to values under one key, so HSET user:1 age 31 updates just that field with a single O(1) command, no need to read-modify-write the whole object. A JSON string (b) works but forces reading and rewriting the entire blob for any single-field change. A list (c) has no concept of named fields and would grow unbounded. A set (d) has no field-value structure and doesn't support partial field updates cleanly.
Redis Data StructuresDifficulty 1
What guarantee does a Redis Set (as opposed to a List) give you about its members?
  • aMembers are always returned in the order they were inserted
  • bMembers are automatically sorted alphabetically
  • cMembers can appear more than once, like a list
  • dEach member is unique — duplicates are automatically rejected
Explanation:A Redis Set is an unordered collection of unique strings; adding the same member twice with SADD has no effect the second time. There is no insertion-order guarantee (a) and no automatic alphabetical sort (b, that's closer to a Sorted Set's score ordering, and even then it's by score, not alphabetically by default). Duplicates being allowed (c) is exactly what a Set prevents.
Redis Data StructuresDifficulty 2
You want to build a live leaderboard where each player has a numeric score and you need to fetch the top 10 players ordered by score efficiently. Which data type is designed exactly for this?
  • aA plain String per player, then sort client-side in the application
  • bA List, using LPUSH to keep scores roughly in order
  • cA Sorted Set (ZSET), using the score as the ranking value
  • dA Set, since scores don't need to be unique
Explanation:A Sorted Set stores each member with a floating-point score and keeps members ordered by that score internally (via a skip list), so ZRANGE/ZREVRANGE can fetch a top-N slice in O(log N + M). Plain strings (a) push all sorting work to the client and require fetching every player. A List (b) has no concept of score-based ordering — LPUSH only affects position, not rank. A Set (d) has no score at all, so ranking isn't possible.
Redis Data StructuresDifficulty 1
SET counter 10
INCR counter
GET counter

What does the final GET counter return?
  • a"11"
  • b"10"
  • cAn error, because INCR only works on keys created with INCR
  • d"101", because INCR appends 1 as a character
Explanation:INCR parses the string value as an integer and atomically increments it by 1, then stores the result back as a string. "10" becomes 11, stored as "11". INCR works on any string that holds a valid integer, regardless of how the key was created (c is wrong), and it performs numeric increment, not string concatenation (d is wrong).

Test yourself against the 2475-question Database bank.

Start interview