What is the correct way to set a key-value pair named 'mykey' with the value 'myvalue' using redis-py?
Explanation:
The r.set()
method is used to store a value associated with a specific key in Redis. Assuming 'r' is your Redis connection object.
What is the expected return value of 'EXISTS user' if the 'user' key is present in Redis?
Explanation:
The EXISTS
command in Redis returns 1 if the key exists and 0 if it doesn't. It doesn't use boolean values.
How do you set a key to expire after 20 seconds in Redis?
Explanation:
The EXPIRE
command is used to set an expiration time (in seconds) for a key. In this case, EXPIRE key 20
would make the 'key' expire after 20 seconds.
What is a potential drawback of using only RDB snapshots for persistence in Redis?
Explanation:
If your Redis server crashes, you'll only recover data up to the last successful RDB snapshot. Any writes after the snapshot might be lost.
What is the primary effect of renaming a key in Redis?
Explanation:
Renaming a key only affects how it is identified within Redis. The data type, value, and expiration time remain unchanged.
What file extension is typically used for Redis's Append-Only File?
Explanation:
Redis AOF files, containing the write operation logs, are conventionally saved with the '.aof' extension.
Which command is used to decrease the value of a key by 1 in Redis?
Explanation:
DECR
is the command in Redis specifically designed to decrement the value of a key by 1.
After installing Redis, what command is commonly used to start the Redis server?
Explanation:
The redis-server
command is used to initiate the Redis server process, making it ready to accept connections and process commands.
Which method is used to check if a key exists in a Redis database using redis-py?
Explanation:
The r.exists()
method checks if the provided key exists within the Redis database, returning 1 if it does and 0 if not. 'r' is your Redis connection object.
What is the correct syntax to set a key-value pair in Redis where the key is 'name' and the value is 'John'?
Explanation:
In Redis, the SET
command is used to set a key-value pair. The syntax is SET key value
.
How does Redis differ from a traditional relational database like MySQL?
Explanation:
Redis's flexibility shines in its schema-less nature, allowing you to store data without predefined structures. MySQL, as a relational database, requires a defined schema.
How do you delete a key-value pair in Redis where the key is 'city'?
Explanation:
The DELETE
command is used to remove key-value pairs from Redis. You specify the key you want to delete.
You need to store a leaderboard with scores for players. Which Redis data type is most appropriate?
Explanation:
Sorted Sets are designed for storing elements with scores, allowing efficient retrieval of top scores or ranges.
What is the result of executing 'INCR counter' if the 'counter' key does not exist in Redis?
Explanation:
If the key doesn't exist, INCR
treats it as if it had a value of 0 and increments it to 1.
What is the purpose of the SADD
command in Redis?
Explanation:
SADD
adds elements to a set. If the element already exists, the command does not have any effect.