Bird
0
0

Which of the following is the correct syntax to subscribe to a Redis channel in Flask using redis-py?

easy📝 Syntax Q3 of 15
Flask - Background Tasks
Which of the following is the correct syntax to subscribe to a Redis channel in Flask using redis-py?
Apubsub = redis_client.pubsub(); pubsub.subscribe('channel')
Bredis_client.subscribe('channel')
Cpubsub = redis_client.subscribe('channel')
Dredis_client.pubsub('channel')
Step-by-Step Solution
Solution:
  1. Step 1: Recall redis-py subscription syntax

    To subscribe, create a pubsub object then call subscribe on it.
  2. Step 2: Check options

    Only pubsub = redis_client.pubsub(); pubsub.subscribe('channel') correctly creates pubsub and subscribes. Others misuse methods or parameters.
  3. Final Answer:

    pubsub = redis_client.pubsub(); pubsub.subscribe('channel') -> Option A
  4. Quick Check:

    Subscribe uses pubsub object then subscribe method [OK]
Quick Trick: Use pubsub() then subscribe() to listen to Redis channels [OK]
Common Mistakes:
MISTAKES
  • Calling subscribe directly on redis_client
  • Passing channel to pubsub() constructor
  • Assigning subscribe() return to pubsub

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes