Complete the code to connect to a Redis server running on localhost.
import redis r = redis.Redis(host=[1], port=6379)
The Redis client connects to the Redis server on the local machine using the hostname "localhost".
Complete the code to set a key "user" with value "Alice" in Redis.
r.set([1], "Alice")
The key "user" is used to store the value "Alice" in Redis.
Fix the error in the code to get the value of key "user" from Redis.
value = r.get([1]) print(value.decode('utf-8'))
The key must be a string in quotes when calling r.get(). Without quotes, it is treated as a variable which causes an error.
Fill both blanks to increment the integer value stored at key "counter" by 1.
r.[1]([2])
decr which decreases the value.The incr method increments the integer value stored at the given key. The key is "counter" as specified.
Fill all three blanks to create a Redis hash named "session" with fields "user", "status", and "count".
r.hset([1], mapping=[2]: "active", [3]: 5})
The hash key is "session". The fields include "status" with value "active" and "count" with value 5. The field "user" is not included in the mapping here.