Challenge - 5 Problems
Redis Counter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the value after incrementing a counter?
Given a Redis key
counter with initial value 5, what will be the value after running INCR counter once?Redis
SET counter 5
INCR counter
GET counterAttempts:
2 left
💡 Hint
INCR adds 1 to the current integer value stored at the key.
✗ Incorrect
The INCR command increases the integer value stored at the key by 1. Starting from 5, it becomes 6.
❓ query_result
intermediate1:30remaining
What happens when DECR is used on a non-existing key?
If the Redis key
visits does not exist, what will be the result of DECR visits?Redis
DEL visits DECR visits GET visits
Attempts:
2 left
💡 Hint
INCR and DECR treat missing keys as zero before operation.
✗ Incorrect
When DECR is called on a non-existing key, Redis treats it as 0 and subtracts 1, resulting in -1.
📝 Syntax
advanced2:00remaining
Which command sequence correctly increments a counter only if it exists?
You want to increment the Redis key
score only if it already exists. Which sequence achieves this without creating the key if missing?Attempts:
2 left
💡 Hint
Check if the key exists before incrementing.
✗ Incorrect
Option A checks if the key exists before incrementing, preventing creation if missing. INCR alone creates the key with value 1 if missing.
❓ query_result
advanced1:30remaining
What is the final value after multiple increments and decrements?
Starting with
counter set to 10, what is the value after these commands?
INCR counter
DECR counter
DECR counter
INCR counterRedis
SET counter 10
INCR counter
DECR counter
DECR counter
INCR counter
GET counterAttempts:
2 left
💡 Hint
Count how many increments and decrements happen.
✗ Incorrect
Starting at 10: +1 → 11, -1 → 10, -1 → 9, +1 → 10 final value.
🧠 Conceptual
expert2:00remaining
Why might using INCR on a key storing a non-integer value cause an error?
Consider a Redis key
user:count storing the string value hello. What happens if you run INCR user:count and why?Redis
SET user:count hello INCR user:count
Attempts:
2 left
💡 Hint
INCR expects the key to hold an integer value or be missing.
✗ Incorrect
INCR fails with an error if the key holds a non-integer string because it cannot convert it to a number.