Bird
0
0

You want to implement a task queue in Flask using Redis. Which approach correctly uses Redis to enqueue and dequeue tasks?

hard📝 Application Q8 of 15
Flask - Background Tasks
You want to implement a task queue in Flask using Redis. Which approach correctly uses Redis to enqueue and dequeue tasks?
AUse HSET to add tasks and HGET to remove tasks
BUse SADD to add tasks and SPOP to remove tasks
CUse ZADD to add tasks and ZRANGE to remove tasks
DUse LPUSH to add tasks and BRPOP to remove tasks
Step-by-Step Solution
Solution:
  1. Step 1: Identify Redis commands for queue

    LPUSH adds to the left of a list, BRPOP blocks and pops from the right, perfect for queues.
  2. Step 2: Evaluate other commands

    SADD/SPOP are for sets, HSET/HGET for hashes, ZADD/ZRANGE for sorted sets, none fit queue pattern.
  3. Final Answer:

    Use LPUSH to add tasks and BRPOP to remove tasks -> Option D
  4. Quick Check:

    Redis queue = LPUSH + BRPOP [OK]
Quick Trick: LPUSH adds, BRPOP removes tasks in Redis queue [OK]
Common Mistakes:
MISTAKES
  • Using sets or hashes for queues
  • Confusing ZRANGE with removal
  • Not using blocking pop for dequeue

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes