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 code?
Consider this Redis pipeline code using a client library:
What is the value of
pipe = client.pipeline()
pipe.set('key1', 'value1')
pipe.get('key1')
pipe.set('key2', 'value2')
pipe.get('key2')
results = pipe.execute()What is the value of
results after execution?Redis
pipe = client.pipeline() pipe.set('key1', 'value1') pipe.get('key1') pipe.set('key2', 'value2') pipe.get('key2') results = pipe.execute()
Attempts:
2 left
💡 Hint
Remember that
set returns True on success and get returns bytes.✗ Incorrect
In Redis pipelines,
set commands return True if successful, and get commands return the stored value as bytes. The results list matches the order of commands.🧠 Conceptual
intermediate1:30remaining
Why use pipelines in Redis client libraries?
Which of the following is the main reason to use pipelines in Redis client libraries?
Attempts:
2 left
💡 Hint
Think about how network communication affects performance.
✗ Incorrect
Pipelines group multiple commands to send them in one network call, reducing latency and improving performance.
📝 Syntax
advanced1:30remaining
Identify the syntax error in this Redis pipeline code snippet
What is wrong with this Redis pipeline code?
pipe = client.pipeline()
pipe.set('key', 'value')
pipe.get('key')
results = pipe.executeAttempts:
2 left
💡 Hint
Check how methods are called in Python.
✗ Incorrect
The
execute method must be called with parentheses to run the pipeline. Missing parentheses means results is a method reference, not the result.❓ optimization
advanced2:00remaining
How to optimize multiple independent Redis commands using pipelines?
You want to set 100 keys with different values in Redis efficiently. Which approach is best?
Attempts:
2 left
💡 Hint
Think about reducing network calls without complex scripting.
✗ Incorrect
Pipelines batch commands to reduce network overhead. Lua scripts add complexity and transactions add overhead when atomicity is not needed.
🔧 Debug
expert2:30remaining
Why does this Redis pipeline code raise a TypeError?
Examine this code:
It raises
pipe = client.pipeline()
pipe.set('key', 'value')
pipe.get('key')
results = pipe.execute()
print(results[1].decode())It raises
TypeError: decode() argument must be str, not None. Why?Attempts:
2 left
💡 Hint
Check if the key was actually set before getting.
✗ Incorrect
If the key was not set or expired before get, get returns None. Calling decode() on None causes TypeError.