Bird
Raised Fist0
Redisquery~20 mins

Redis data model (key-value) - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Redis Key-Value Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Redis Key-Value Storage

Which statement best describes how Redis stores data in its key-value model?

ARedis stores data as keys linked exclusively to JSON documents.
BRedis stores data as keys with associated string values only, no other data types.
CRedis stores data only as keys with numeric values for fast calculations.
DRedis stores data as keys associated with various data types like strings, lists, sets, hashes, and sorted sets.
Attempts:
2 left
💡 Hint

Think about the flexibility Redis offers beyond simple strings.

❓ dax_lod_result
intermediate
2:00remaining
Calculating Unique Keys in Redis-like Model

Given a Redis-like key-value store where keys represent user IDs and values represent user roles, which DAX measure correctly counts unique user IDs?

Redis
UniqueUsers = DISTINCTCOUNT('UserRoles'[UserID])
AUniqueUsers = SUM('UserRoles'[UserID])
BUniqueUsers = DISTINCTCOUNT('UserRoles'[UserID])
CUniqueUsers = COUNT('UserRoles'[UserID])
DUniqueUsers = COUNTROWS('UserRoles')
Attempts:
2 left
💡 Hint

Counting unique keys means counting distinct user IDs.

❓ visualization
advanced
2:00remaining
Visualizing Redis Key Expiry Distribution

You have a Redis database with keys that have different expiry times. Which visualization best shows the distribution of key expiry times to help monitor key lifetimes?

AA histogram showing the count of keys grouped by expiry time ranges.
BA line chart showing expiry times on the x-axis and number of keys on the y-axis over time.
CA pie chart showing the percentage of keys per expiry time category.
DA scatter plot showing keys on x-axis and expiry time on y-axis.
Attempts:
2 left
💡 Hint

Think about how to show frequency distribution of expiry times.

❓ data_modeling
advanced
2:00remaining
Modeling User Sessions in Redis Key-Value Store

You want to model user sessions in Redis using key-value pairs. Each session has a unique session ID, user ID, and expiration time. Which Redis data structure and key design is best for efficient session lookup and expiry?

AUse hash keys with session ID as key and fields for user ID and expiry timestamp, setting Redis key expiry for session timeout.
BUse list keys with session IDs as list elements and separate keys for user IDs and expiry times.
CUse string keys with session ID as key and JSON string as value containing user ID and expiry timestamp.
DUse set keys with user IDs as members and session IDs stored as values in separate keys.
Attempts:
2 left
💡 Hint

Consider how Redis expiry works and how to store multiple fields per session.

🔧 Debug
expert
2:00remaining
Identifying Error in Redis Key Expiry Command Usage

Which Redis command usage will cause an error when trying to set a key with expiry?

Options:
ASET mykey "value" EX 60
BSET mykey "value" PX 60000
CSET mykey EXPIRE 60 "value"
DSETEX mykey 60 "value"
Attempts:
2 left
💡 Hint

Check the correct syntax for setting expiry with SET command.

Practice

(1/5)
1. What is the main purpose of the key in a Redis key-value data model?
easy
A. To store multiple values together
B. To uniquely identify the stored data
C. To perform calculations on data
D. To format the data for display

Solution

  1. Step 1: Understand the role of keys in Redis

    Keys in Redis act as unique names that identify each piece of data stored.
  2. Step 2: Differentiate keys from values

    Values hold the actual data, while keys are used to find or access that data quickly.
  3. Final Answer:

    To uniquely identify the stored data -> Option B
  4. Quick Check:

    Key = Unique identifier [OK]
Hint: Keys uniquely name data for fast access [OK]
Common Mistakes:
  • Thinking keys store multiple values
  • Confusing keys with data formatting
  • Assuming keys perform calculations
2. Which of the following is the correct Redis command syntax to set a key named user:1 with value John?
easy
A. STORE user:1 John
B. GET user:1 John
C. SET user:1 John
D. SET user:1 = John

Solution

  1. Step 1: Recall the Redis command to store a key-value pair

    The command to set a key with a value is SET key value.
  2. Step 2: Check each option's syntax

    SET user:1 John matches the correct syntax. Options A, B, and C use incorrect commands or syntax.
  3. Final Answer:

    SET user:1 John -> Option C
  4. Quick Check:

    SET key value = correct syntax [OK]
Hint: Use SET key value to store data [OK]
Common Mistakes:
  • Using GET instead of SET to store data
  • Adding '=' sign in command
  • Using STORE command which doesn't exist
3. Given the following Redis commands executed in order:
SET counter 10
INCR counter
GET counter
What will be the output of the last command?
medium
A. 11
B. 10
C. counter
D. Error

Solution

  1. Step 1: Analyze the commands executed

    First, SET counter 10 sets the key counter to string "10". Then, INCR counter increments the numeric value by 1.
  2. Step 2: Understand the effect of INCR and GET

    INCR converts the string "10" to number 10, adds 1 to make 11, and stores it back. GET returns the current value, which is now "11".
  3. Final Answer:

    11 -> Option A
  4. Quick Check:

    10 + 1 = 11 [OK]
Hint: INCR adds 1 to numeric string values [OK]
Common Mistakes:
  • Assuming GET returns the key name
  • Thinking INCR works on non-numeric strings
  • Expecting no change after INCR
4. You run the command INCR mykey but get an error. Which of the following is the most likely cause?
medium
A. The command syntax is incorrect
B. The key mykey does not exist
C. The Redis server is down
D. The value of mykey is not an integer

Solution

  1. Step 1: Understand INCR command requirements

    INCR requires the key's value to be an integer or not exist (which initializes it to 0).
  2. Step 2: Identify error cause

    If the key exists but holds a non-integer value (like a string), INCR will cause an error.
  3. Final Answer:

    The value of mykey is not an integer -> Option D
  4. Quick Check:

    INCR needs integer value [OK]
Hint: INCR fails if value is non-integer [OK]
Common Mistakes:
  • Assuming missing key causes error
  • Blaming server status without checking value
  • Thinking syntax is wrong when command is correct
5. You want to store user session data in Redis using the key-value model. Which approach best ensures each session is uniquely stored and easily retrieved?
hard
A. Use a key pattern like session:{session_id} with the session data as the value
B. Store all sessions in a single key as a JSON string
C. Use the same key session for all users and overwrite values
D. Store session data as keys and user IDs as values

Solution

  1. Step 1: Understand unique key requirements for sessions

    Each user session must have a unique key to avoid overwriting and allow quick access.
  2. Step 2: Evaluate options for storing sessions

    Use a key pattern like session:{session_id} with the session data as the value uses a unique key pattern with session IDs, which is best practice. Store all sessions in a single key as a JSON string stores all sessions in one key, making access slow and complex. Use the same key session for all users and overwrite values overwrites data. Store session data as keys and user IDs as values reverses key-value roles, which is inefficient.
  3. Final Answer:

    Use a key pattern like session:{session_id} with the session data as the value -> Option A
  4. Quick Check:

    Unique keys per session = best practice [OK]
Hint: Use unique keys with session IDs for each session [OK]
Common Mistakes:
  • Storing all sessions in one key
  • Overwriting session data with same key
  • Confusing keys and values roles
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard