Expire Keys In Redis Cache

RedisBeginner
Practice Now

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:topic1 to Redis Basics and then set its expiration time to 3600 seconds.

Requirements

  1. Connect to the Redis server using the redis-cli command.
  2. Use the SET command to set the key trending:topic1 to the value Redis Basics.
  3. Use the EXPIRE command to set the expiration time of the key trending:topic1 to 3600 seconds.
  4. Exit the redis-cli interface using the exit command.

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-cli command to connect to the Redis server.
  • The SET command sets the value of a key.
  • The EXPIRE command sets the expiration time of a key in seconds.
✨ Check Solution and Practice

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.