Here’s a short practice on using Redis:
- Open a terminal or command prompt and start the Redis CLI (Command Line Interface) by typing
redis-cli
. - Set a key-value pair in Redis by using the following command:
SET favorite_color blue
. - Retrieve the value of the key by using the following command:
GET favorite_color
. The output should be “blue”. - Add an item to a list by using the following command:
LPUSH fruits apple
. - Add another item to the same list by using the following command:
LPUSH fruits banana
. - Retrieve all items in the list by using the following command:
LRANGE fruits 0 -1
. The output should be “banana”, “apple”. - Create a channel by using the following command:
SUBSCRIBE chat_channel
. - Publish a message to the channel by using the following command:
PUBLISH chat_channel Hello!
. - You should receive the message you just published in the terminal or command prompt you used to start the Redis CLI. The output should be “Hello!”.
This practice will give you a basic understanding of how to use Redis and some of its core features. Keep practicing and exploring the various commands and features available in Redis to become more proficient in using this powerful data structure store.