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 command sequence?
Consider the following Redis pipeline commands executed in order:
1. SET user:1 "Alice"
2. INCR visits:1
3. GET user:1
4. GET visits:1
What will be the output of the pipeline?
1. SET user:1 "Alice"
2. INCR visits:1
3. GET user:1
4. GET visits:1
What will be the output of the pipeline?
Redis
pipeline = redis_client.pipeline() pipeline.set('user:1', 'Alice') pipeline.incr('visits:1') pipeline.get('user:1') pipeline.get('visits:1') results = pipeline.execute()
Attempts:
2 left
💡 Hint
Remember that Redis returns bytes for GET commands in Python clients.
✗ Incorrect
The SET command returns True on success, INCR returns the incremented integer, and GET returns bytes representing the stored string values.
🧠 Conceptual
intermediate1:30remaining
Why use pipelines in Redis?
Which of the following best explains the main benefit of using pipelines in Redis?
Attempts:
2 left
💡 Hint
Think about network communication between client and server.
✗ Incorrect
Pipelines batch commands to send them in one go, reducing the number of network trips and improving performance.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this Redis pipeline code
Which option contains the correct syntax to add commands to a Redis pipeline in Python?
Redis
pipeline = redis_client.pipeline() pipeline.set('key1', 'value1') pipeline.incr('counter') results = pipeline.execute()
Attempts:
2 left
💡 Hint
Check how the execute method is called and assigned.
✗ Incorrect
The execute method must be called with parentheses to run the pipeline and its result assigned to a variable if needed.
🔧 Debug
advanced2:30remaining
Why does this Redis pipeline code raise an error?
Given this code snippet:
pipeline = redis_client.pipeline()
pipeline.set('count', 10)
pipeline.incr('count')
pipeline.get('count')
results = pipeline.execute()
It raises a TypeError on the INCR command. Why?
pipeline = redis_client.pipeline()
pipeline.set('count', 10)
pipeline.incr('count')
pipeline.get('count')
results = pipeline.execute()
It raises a TypeError on the INCR command. Why?
Attempts:
2 left
💡 Hint
Consider the data type stored at 'count' before INCR.
✗ Incorrect
INCR expects the key to hold a string representing an integer. Setting 'count' to an integer type directly causes a type mismatch error.
❓ optimization
expert3:00remaining
Optimizing multiple Redis commands with pipeline
You want to set 1000 keys with values and then retrieve them all. Which approach is the most efficient?
Attempts:
2 left
💡 Hint
Think about reducing network round trips without blocking the server.
✗ Incorrect
Pipelines reduce network trips by batching commands but do not block the server like transactions or Lua scripts might.