Challenge - 5 Problems
Redis Pipeline Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this Redis pipeline?
Consider the following Redis pipeline commands executed in sequence:
1. SET key1 10
2. INCR key1
3. GET key1
4. DEL key1
5. GET key1
What is the output returned by the pipeline?
1. SET key1 10
2. INCR key1
3. GET key1
4. DEL key1
5. GET key1
What is the output returned by the pipeline?
Redis
pipeline = redis_client.pipeline() pipeline.set('key1', '10') pipeline.incr('key1') pipeline.get('key1') pipeline.delete('key1') pipeline.get('key1') results = pipeline.execute()
Attempts:
2 left
💡 Hint
Remember that INCR increments the string value stored at the key and returns the new value. DEL returns the number of keys removed. GET returns None if the key does not exist.
✗ Incorrect
The SET command returns True on success. INCR increments '10' to 11 and returns 11. GET returns the byte string b'11'. DEL removes the key and returns 1 (number of keys deleted). The final GET returns None because the key no longer exists.
🧠 Conceptual
intermediate1:30remaining
Why use Redis pipelines?
Which of the following best explains the main advantage of using Redis pipelines?
Attempts:
2 left
💡 Hint
Think about how network communication affects command execution speed.
✗ Incorrect
Pipelines batch multiple commands and send them together, reducing the number of network round trips and thus improving performance. They do not provide automatic retries, encryption, or parallel execution across servers.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this Redis pipeline code
Which option contains a syntax error that will cause the pipeline execution to fail?
Redis
pipeline = redis_client.pipeline() pipeline.set('count', 5) pipeline.incr('count') pipeline.get('count') results = pipeline.execute()
Attempts:
2 left
💡 Hint
Check how the execute method is called.
✗ Incorrect
Option B misses the parentheses after execute, so it references the method without calling it, causing results to be a method object instead of the command results. This will cause errors if results are used as data.
❓ optimization
advanced2:30remaining
Optimizing multiple Redis commands with pipelines
You want to increment 100 keys named 'counter1' to 'counter100' by 1 each. Which approach is the most efficient?
Attempts:
2 left
💡 Hint
Consider network overhead and atomicity requirements.
✗ Incorrect
Using a pipeline batches commands reducing network overhead and improves performance. MULTI/EXEC provides atomicity but has similar network overhead. Lua scripting can be efficient but requires scripting knowledge and may be more complex. Running commands one by one is slow due to many round trips.
🔧 Debug
expert3:00remaining
Why does this Redis pipeline return unexpected results?
Given this pipeline code:
pipeline.set('x', '5')
pipeline.incr('x')
pipeline.get('x')
pipeline.set('x', 'hello')
pipeline.incr('x')
results = pipeline.execute()
What will happen and why?
pipeline.set('x', '5')
pipeline.incr('x')
pipeline.get('x')
pipeline.set('x', 'hello')
pipeline.incr('x')
results = pipeline.execute()
What will happen and why?
Redis
pipeline = redis_client.pipeline() pipeline.set('x', '5') pipeline.incr('x') pipeline.get('x') pipeline.set('x', 'hello') pipeline.incr('x') results = pipeline.execute()
Attempts:
2 left
💡 Hint
What happens if you try to increment a key holding a non-numeric string?
✗ Incorrect
The first INCR increments '5' to 6 successfully. The GET returns b'6'. Then the key is set to 'hello'. The next INCR tries to increment 'hello', which is not a number, causing a Redis error. The pipeline execution raises a Redis error at that command.