Introduction to Redis CLI
Daniel Hayes
Full-Stack Engineer · Leapcell

Key Takeaways
- Redis CLI is a command-line tool for interacting with Redis servers.
- It supports interactive use, scripting, and advanced features like monitoring.
- Secure connections and authentication are essential for safe Redis CLI usage.
Redis CLI (redis-cli
) is a powerful command-line interface tool that allows users to interact directly with a Redis server. Whether you're managing data, monitoring server performance, or debugging applications, redis-cli
provides a straightforward and efficient means to execute Redis commands and receive immediate feedback.
Getting Started with Redis CLI
Installation
To use redis-cli
, you need to have Redis installed on your system. Most package managers include redis-cli
as part of the Redis package. For instance, on Ubuntu, you can install it using:
sudo apt-get update sudo apt-get install redis
On macOS, you might use Homebrew:
brew install redis
For Windows users, it's recommended to use the Windows Subsystem for Linux (WSL) and install Redis within that environment .
Connecting to Redis
By default, redis-cli
connects to the Redis server at 127.0.0.1
on port 6379
. To connect to a different host or port, use the -h
and -p
options:
redis-cli -h <hostname> -p <port>
If your Redis server requires authentication, you can provide the password using the -a
option:
redis-cli -a <password>
Alternatively, for enhanced security, set the REDISCLI_AUTH
environment variable:
export REDISCLI_AUTH=<password> redis-cli
Modes of Operation
Interactive Mode
Launching redis-cli
without additional arguments starts it in interactive mode, presenting a prompt where you can enter Redis commands:
$ redis-cli 127.0.0.1:6379>
In this mode, you can:
- Execute any Redis command directly.
- Use the
Tab
key for command auto-completion. - Navigate through command history using the up and down arrow keys.
- Access command-specific help using the
HELP
command.
Command-Line Mode
You can also execute a single Redis command directly from the shell:
redis-cli <command> [arguments]
For example:
redis-cli PING
This mode is useful for scripting and automation purposes.
Common Commands
Here are some frequently used Redis commands:
PING
: Check if the server is running.SET key value
: Set the value of a key.GET key
: Retrieve the value of a key.DEL key
: Delete a key.EXISTS key
: Check if a key exists.INCR key
: Increment the integer value of a key.DECR key
: Decrement the integer value of a key.FLUSHALL
: Remove all keys from all databases.
For example:
127.0.0.1:6379> SET mykey "Hello" OK 127.0.0.1:6379> GET mykey "Hello"
Advanced Features
Running Commands from a File
You can execute multiple Redis commands from a file:
cat commands.txt | redis-cli
Where commands.txt
contains:
SET key1 "value1"
SET key2 "value2"
GET key1
GET key2
Monitoring Server Activity
Use the MONITOR
command to see real-time server activity:
redis-cli MONITOR
This is particularly useful for debugging and understanding how your application interacts with Redis.
Checking Server Statistics
Retrieve server statistics using the INFO
command:
redis-cli INFO
This provides details about memory usage, connected clients, and more.
Connecting Over TLS
If your Redis server is configured to use TLS, connect using the --tls
option:
redis-cli --tls -h <hostname> -p <port> -a <password>
For servers requiring client certificates, include the --cert
and --key
options:
redis-cli --tls -h <hostname> -p <port> --cert <client-cert.pem> --key <client-key.pem> --cacert <ca-cert.pem>
Conclusion
Redis CLI is an essential tool for developers and system administrators working with Redis. Its versatility and ease of use make it ideal for tasks ranging from simple data manipulation to complex server monitoring and debugging. By mastering redis-cli
, you can efficiently manage your Redis instances and ensure optimal performance for your applications.
FAQs
Use redis-cli -a <password>
or set REDISCLI_AUTH
environment variable.
Yes, use the MONITOR
command to see real-time server activity.
Use the --tls
option along with certificate options if needed.
We are Leapcell, your top choice for hosting backend projects.
Leapcell is the Next-Gen Serverless Platform for Web Hosting, Async Tasks, and Redis:
Multi-Language Support
- Develop with Node.js, Python, Go, or Rust.
Deploy unlimited projects for free
- pay only for usage — no requests, no charges.
Unbeatable Cost Efficiency
- Pay-as-you-go with no idle charges.
- Example: $25 supports 6.94M requests at a 60ms average response time.
Streamlined Developer Experience
- Intuitive UI for effortless setup.
- Fully automated CI/CD pipelines and GitOps integration.
- Real-time metrics and logging for actionable insights.
Effortless Scalability and High Performance
- Auto-scaling to handle high concurrency with ease.
- Zero operational overhead — just focus on building.
Explore more in the Documentation!
Follow us on X: @LeapcellHQ