0
0
Redisquery~10 mins

Redis with Python (redis-py) - Interactive Code Practice

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

Complete the code to connect to a Redis server running on localhost.

Redis
import redis
r = redis.Redis(host=[1], port=6379)
Drag options to blanks, or click blank then click option'
A"0.0.0.0"
B"127.0.0.1"
C"redis"
D"localhost"
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect hostname that does not point to the local machine.
Leaving the host parameter empty.
2fill in blank
medium

Complete the code to set a key "user" with value "Alice" in Redis.

Redis
r.set([1], "Alice")
Drag options to blanks, or click blank then click option'
A"user"
B"name"
C"username"
D"id"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different key name than "user".
Forgetting to put the key name in quotes.
3fill in blank
hard

Fix the error in the code to get the value of key "user" from Redis.

Redis
value = r.get([1])
print(value.decode('utf-8'))
Drag options to blanks, or click blank then click option'
Auser
B"user"
C'user'
Duser_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using the key name without quotes causing a NameError.
Using a variable name that is not defined.
4fill in blank
hard

Fill both blanks to increment the integer value stored at key "counter" by 1.

Redis
r.[1]([2])
Drag options to blanks, or click blank then click option'
Aincr
Bdecr
C"counter"
D"count"
Attempts:
3 left
💡 Hint
Common Mistakes
Using decr which decreases the value.
Using the wrong key name.
5fill in blank
hard

Fill all three blanks to create a Redis hash named "session" with fields "user", "status", and "count".

Redis
r.hset([1], mapping=[2]: "active", [3]: 5})
Drag options to blanks, or click blank then click option'
A"session"
B"user"
C"count"
D"status"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up field names or hash key name.
Not using quotes around string keys.