0
0
Redisquery~20 mins

INCRBY and DECRBY in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Increment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1:30remaining
What is the result of INCRBY on a key with an integer value?
Given a Redis key counter with value 10, what will be the value of counter after running INCRBY counter 5?
Redis
SET counter 10
INCRBY counter 5
GET counter
A15
B5
C10
DError: value is not an integer
Attempts:
2 left
💡 Hint
INCRBY adds the given number to the current integer value stored at the key.
query_result
intermediate
1:30remaining
What happens when DECRBY is used on a non-existing key?
What will be the value of key score after running DECRBY score 3 if score does not exist before?
Redis
DEL score
DECRBY score 3
GET score
A3
B0
C-3
DError: key does not exist
Attempts:
2 left
💡 Hint
Redis treats non-existing keys as 0 for increment/decrement commands.
📝 Syntax
advanced
1:00remaining
Which command syntax is correct for incrementing a key by 10?
Choose the correct Redis command to increase the value of key visits by 10.
AINCRBY visits 10
BINCR visits 10
CINCRBY 10 visits
DINCRBY(visits, 10)
Attempts:
2 left
💡 Hint
The syntax is INCRBY key increment.
query_result
advanced
1:30remaining
What error occurs when INCRBY is used on a key holding a string?
If key name holds the string value "Alice", what happens when running INCRBY name 1?
Redis
SET name "Alice"
INCRBY name 1
AValue becomes 0
BValue becomes "Alice1"
CValue becomes 1
DError: value is not an integer or out of range
Attempts:
2 left
💡 Hint
INCRBY only works on keys holding integer values.
🧠 Conceptual
expert
2:00remaining
How does Redis handle concurrent INCRBY and DECRBY commands on the same key?
Consider multiple clients running INCRBY counter 2 and DECRBY counter 1 concurrently on the same key counter. What guarantees does Redis provide about the final value?
ARedis queues commands but applies only increments or only decrements, ignoring the other.
BRedis guarantees atomicity; all increments and decrements are applied without race conditions, so the final value is consistent.
CRedis may lose some increments or decrements due to race conditions, so the final value is unpredictable.
DRedis locks the key permanently after the first command, blocking others indefinitely.
Attempts:
2 left
💡 Hint
Redis commands like INCRBY and DECRBY are atomic operations.