Recall & Review
beginner
What does the Redis command INCR do?
INCR increases the integer value of a key by 1. If the key does not exist, it is set to 0 before incrementing.
Click to reveal answer
beginner
What happens if you use DECR on a key that does not exist in Redis?
The key is set to 0 first, then decreased by 1, resulting in a value of -1.
Click to reveal answer
intermediate
Can INCR and DECR be used on keys holding non-integer values?
No. INCR and DECR only work on keys holding integer values. Using them on non-integer values causes an error.
Click to reveal answer
intermediate
How would you atomically increase a counter by 5 in Redis?
Use the INCRBY command with the key and 5 as arguments, e.g., INCRBY key 5.
Click to reveal answer
beginner
Why are INCR and DECR commands useful for counters in Redis?
They provide a simple, fast, and atomic way to increase or decrease counters without race conditions.
Click to reveal answer
What is the result of INCR on a key that does not exist?
✗ Incorrect
INCR sets the key to 0 first, then increments it by 1, so the final value is 1.
Which command decreases the value of a Redis key by 1?
✗ Incorrect
DECR decreases the integer value of a key by 1.
What happens if you run INCR on a key holding the string 'hello'?
✗ Incorrect
INCR only works on integer values; using it on a non-integer string causes an error.
How can you increase a Redis counter by 10 in one command?
✗ Incorrect
INCRBY key 10 increases the key's value by 10 atomically.
Why is using INCR and DECR commands better than getting and setting values manually?
✗ Incorrect
INCR and DECR are atomic operations, so they prevent race conditions in concurrent environments.
Explain how INCR and DECR commands work in Redis and why they are useful for counters.
Think about how counters change and why atomicity matters.
You got /5 concepts.
Describe what happens if you use INCR or DECR on a key with a non-integer value in Redis.
Consider data types and command restrictions.
You got /4 concepts.