Challenge - 5 Problems
Redis HINCRBY Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the result of this HINCRBY command?
Given a Redis hash key
user:1000 with field score set to 10, what will be the value of score after running HINCRBY user:1000 score 5?Redis
HSET user:1000 score 10 HINCRBY user:1000 score 5 HGET user:1000 score
Attempts:
2 left
💡 Hint
HINCRBY adds the increment to the current integer value stored in the field.
✗ Incorrect
HINCRBY increments the numeric value stored in the specified field by the given amount. Starting from 10, adding 5 results in 15.
❓ query_result
intermediate2:00remaining
What happens if the field does not exist?
If the Redis hash
user:1001 does not have the field points, what will be the result of HINCRBY user:1001 points 7?Redis
HINCRBY user:1001 points 7 HGET user:1001 points
Attempts:
2 left
💡 Hint
HINCRBY treats missing fields as zero before incrementing.
✗ Incorrect
If the field does not exist, Redis treats its value as 0 and increments by the given amount, so the new value is 7.
📝 Syntax
advanced2:00remaining
Which HINCRBY command is syntactically correct?
Choose the correct syntax to increment the field
level by 3 in the hash game:player1.Attempts:
2 left
💡 Hint
The syntax is HINCRBY key field increment.
✗ Incorrect
The correct syntax is HINCRBY followed by the key, then the field, then the increment number.
❓ query_result
advanced2:00remaining
What error occurs if the field contains a non-integer value?
If the field
score in hash user:1002 contains the string ten, what happens when running HINCRBY user:1002 score 1?Redis
HSET user:1002 score ten HINCRBY user:1002 score 1
Attempts:
2 left
💡 Hint
HINCRBY requires the field value to be an integer string.
✗ Incorrect
If the field value is not an integer string, HINCRBY returns an error.
🧠 Conceptual
expert3:00remaining
Why is HINCRBY preferred over GET and SET for incrementing numeric fields?
Consider incrementing a numeric field in a Redis hash. Why is using
HINCRBY better than using HGET to get the value, incrementing it in the client, and then HSET to update it?Attempts:
2 left
💡 Hint
Think about what happens if multiple clients increment at the same time.
✗ Incorrect
HINCRBY performs the increment atomically inside Redis, avoiding race conditions that can happen if you GET, increment, and SET separately.