Introduction
In this challenge, you'll simulate a social media app using Redis to cache trending topics. The goal is to set a key representing a trending topic and configure it to expire after a specific duration.
Specifically, you'll connect to the Redis server using redis-cli, set the value of the key trending:topic1 to Redis Basics, and then set its expiration time to 3600 seconds using the EXPIRE command. Finally, you'll exit the redis-cli interface. The challenge will verify that you correctly set the key and its expiration time by checking the Redis command history.
Expire Keys In Redis Cache
A social media app uses Redis to cache trending topics. Ensure 'trending:topic1' expires in 3600 seconds after being set.
Tasks
- Set the value of key
trending:topic1toRedis Basicsand then set its expiration time to 3600 seconds.
Requirements
- Connect to the Redis server using the
redis-clicommand. - Use the
SETcommand to set the keytrending:topic1to the valueRedis Basics. - Use the
EXPIREcommand to set the expiration time of the keytrending:topic1to 3600 seconds. - Exit the
redis-cliinterface using theexitcommand.
Examples
127.0.0.1:6379> INPUT YOUR COMMAND HERE
OK
127.0.0.1:6379> INPUT YOUR COMMAND HERE
(integer) 1
127.0.0.1:6379> exit
Hints
- Use the
redis-clicommand to connect to the Redis server. - The
SETcommand sets the value of a key. - The
EXPIREcommand sets the expiration time of a key in seconds.
Summary
In this challenge, the task involves setting a key-value pair in Redis and configuring its expiration time. Specifically, the key trending:topic1 is set to the value Redis Basics, and then its expiration is set to 3600 seconds.
The key learning points are using the redis-cli to interact with the Redis server, employing the SET command to assign a value to a key, and utilizing the EXPIRE command to define the key's time-to-live (TTL) in seconds. The verification scripts confirm the correct usage of these commands by checking the Redis command history log.


