Welcome to our comprehensive guide on Redis Commands! In this lesson, we'll delve into the essential Redis commands: SET, GET, DEL, and EXPIRE. These commands are fundamental for anyone looking to work with Redis, a popular open-source, in-memory data structure store.
Redis (Remote Dictionary Server) is an open-source, in-memory data structure store, used as a database, cache, and message broker. It supports various data structures like strings, hashes, lists, sets, and more.
The SET command is used to store a key-value pair in Redis.
SET key valuekey: The unique name of the keyvalue: The value to be associated with the keyExample:
SET name JohnIn this example, we're storing the key name with the value John.
The GET command is used to retrieve the value associated with a key.
GET keykey: The name of the keyExample:
GET nameThis command will return the value John, which is associated with the key name.
The DEL command is used to delete a key-value pair in Redis.
DEL keykey: The name of the key to be deletedExample:
DEL nameThis command will delete the key-value pair associated with the key name.
The EXPIRE command is used to set the time to live (TTL) for a key in seconds.
EXPIRE key secondskey: The name of the keyseconds: The time in seconds after which the key will be deletedExample:
EXPIRE name 60In this example, we're setting the TTL for the key name to 60 seconds. After 60 seconds, the key will be automatically deleted from Redis.
What command is used to store a key-value pair in Redis?
What command is used to retrieve the value associated with a key in Redis?
What command is used to delete a key-value pair in Redis?
What command is used to set the time to live (TTL) for a key in Redis?
Stay tuned for our next lesson, where we'll explore more Redis commands and learn how to use them effectively in real-world projects! 🎉
📝 Remember: The SET, GET, DEL, and EXPIRE commands are fundamental for working with Redis. Use these commands to store, retrieve, delete, and manage the time to live of key-value pairs in Redis.
Happy learning, and see you in the next lesson! 🎯🎉