
{{ $('Map tags to IDs').item.json.title }}
How to Use Redis CLI
The Redis Command Line Interface (CLI) is a powerful tool for interacting with your Redis database. It allows you to execute commands, manage data, and monitor server status. This tutorial will guide you through the basic usage of Redis CLI, including common commands and practices.
1. Installing Redis CLI
The Redis CLI is typically installed alongside the Redis server. To verify the installation, run:
redis-cli --version
If it’s not installed, you can install Redis using:
- For Ubuntu:
sudo apt update sudo apt install redis-server
- For CentOS:
sudo yum install redis
2. Connecting to Redis
To start the Redis CLI, run the following command in your terminal:
redis-cli
If you want to connect to a Redis server running on a different host or port, use:
redis-cli -h hostname -p port
Replace hostname
and port
with the appropriate values (default port is 6379).
3. Basic Redis Commands
Once you are in the Redis CLI, you can start executing commands. Here are some basic commands:
3.1. Setting a Key
To set a key-value pair, use:
SET key value
For example:
SET mykey "Hello, Redis!"
3.2. Getting a Key
To retrieve the value of a key, use:
GET key
Example:
GET mykey
3.3. Deleting a Key
To delete a key from the database, use:
DEL key
Example:
DEL mykey
4. Managing Data Types
Redis supports several data types. Here’s how to handle a list:
4.1. Adding to a List
To add elements to a list:
LPUSH mylist "first"
LPUSH mylist "second"
4.2. Getting the List
To retrieve the elements of a list:
LRANGE mylist 0 -1
This retrieves all elements in mylist
.
5. Monitoring Server Status
You can check the status of your Redis server by running:
INFO
This command provides a detailed report of your Redis instance, including memory usage, connected clients, and more.
6. Conclusion
By following this tutorial, you have learned the basics of using Redis CLI to interact with your Redis database. The command line interface is a powerful tool that provides immediate access to Redis commands and operations. Continue to explore more advanced Redis commands and features to enhance your data management skills!