0
0
Flaskframework~10 mins

Redis as message broker in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Redis client in a Flask app.

Flask
from redis import [1]
Drag options to blanks, or click blank then click option'
ARedis
BClient
CConnection
DBroker
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Client' instead of 'Redis' causes import errors.
Trying to import 'Connection' which is not the main client class.
2fill in blank
medium

Complete the code to create a Redis client instance connecting to localhost.

Flask
redis_client = Redis(host=[1], port=6379, db=0)
Drag options to blanks, or click blank then click option'
A'remotehost'
B'localhost'
C'127.0.0.2'
D'0.0.0.0'
Attempts:
3 left
💡 Hint
Common Mistakes
Using IP addresses other than 127.0.0.1 for local connection.
Using '0.0.0.0' which means all interfaces, not a specific host.
3fill in blank
hard

Fix the error in publishing a message to a Redis channel.

Flask
redis_client.[1]('notifications', 'Hello World!')
Drag options to blanks, or click blank then click option'
Apost
Bsend
Cpublish
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' or 'push' which are not Redis client methods.
Using 'post' which is unrelated to Redis messaging.
4fill in blank
hard

Fill both blanks to subscribe to a Redis channel and listen for messages.

Flask
pubsub = redis_client.[1]()
pubsub.[2]('updates')
Drag options to blanks, or click blank then click option'
Apubsub
Bsubscribe
Clisten
Dsubscribe_channel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listen' instead of 'subscribe' to subscribe to a channel.
Trying to call 'subscribe_channel' which does not exist.
5fill in blank
hard

Fill all three blanks to receive and print messages from a Redis subscription.

Flask
for message in pubsub.[1]():
    if message['[2]'] == 'message':
        print(message['[3]'])
Drag options to blanks, or click blank then click option'
Alisten
Btype
Cdata
Dsubscribe
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'subscribe' instead of 'listen' to receive messages.
Checking wrong keys in the message dictionary.