Installation and the Redis CLI
Introduction
Before you can store a single key, you need a running Redis server and a way to talk to it. This chapter walks you through installing Redis on Linux, macOS, and Windows (via WSL), starting the server, and using the command-line client (redis-cli) to send your first commands. By the end, you will have a local Redis instance running and the confidence to explore its data structures.
Prerequisites
- A terminal (Linux, macOS, or Windows with WSL2)
- Administrator or sudo access for system-wide installs
- Completion of What Is Redis is recommended but not required
Installing Redis
Redis is developed primarily for POSIX systems. The experience is smoothest on Linux and macOS. Windows users should run Redis inside WSL2, which provides a full Linux kernel.
Linux (Ubuntu / Debian)
The official Redis package is available in most distribution repositories.
# Update package lists
sudo apt update
# Install Redis
sudo apt install redis-server -y
# Verify the installed version
redis-server --versionAfter installation, Redis usually starts automatically as a system service.
# Check if the service is running
sudo systemctl status redis-server
# Start it if needed
sudo systemctl start redis-server
# Enable it to start on boot
sudo systemctl enable redis-serverLinux (RHEL / CentOS / Rocky Linux)
# Install from EPEL or default repositories
sudo dnf install redis -y
# Start and enable the service
sudo systemctl start redis
sudo systemctl enable redismacOS (Homebrew)
Homebrew is the most convenient path on macOS.
# Install Homebrew if you have not already: https://brew.sh
# Install Redis
brew install redis
# Start Redis as a background service
brew services start redis
# Or start it manually in the foreground for testing
redis-serverWindows (WSL2)
Redis does not provide a native Windows server. Use WSL2 and follow the Linux instructions above.
# Inside a WSL2 Ubuntu terminal
sudo apt update
sudo apt install redis-server -y
# Start the server
sudo service redis-server startTip
Windows Terminal
If you have not set up WSL2 yet, Microsoft provides a one-line installer: wsl --install in PowerShell. After rebooting, install Ubuntu from the Microsoft Store and return to the Linux steps above.
Building from Source
If you need a version newer than your package manager provides, compile from the official source.
Starting and Connecting to the Server
Once installed, the redis-server binary starts the database and redis-cli opens an interactive shell.
Starting the Server
# Start with the default configuration
redis-server
# Start with a specific configuration file
redis-server /etc/redis/redis.conf
# Start in the background (daemon mode), already the default on most installs
redis-server --daemonize yesWhen the server starts successfully, you will see output similar to:
[1] 01 Jan 2026 00:00:00.000 # Server initialized
[1] 01 Jan 2026 00:00:00.000 * Ready to accept connections tcp port: 6379Port 6379 is the default Redis port.
Your First Ping
Open a second terminal window and run:
redis-cli pingIf the server is running, it replies:
PONGThat is the simplest possible health check. Production monitoring systems often send PING continuously to detect outages.
Interactive Mode
Running redis-cli without arguments drops you into an interactive REPL where you can issue commands and see responses immediately.
redis-cli127.0.0.1:6379> SET name "Ada"
OK
127.0.0.1:6379> GET name
"Ada"
127.0.0.1:6379> DEL name
(integer) 1
127.0.0.1:6379> GET name
(nil)The prompt shows the host, port, and current database index (0 by default). Redis supports 16 logical databases (numbered 0 to 15), though modern best practice favors using a single database and separating concerns with key prefixes.
Essential CLI Options
You do not always need an interactive session. redis-cli accepts flags for one-off commands and remote connections.
| Flag | Purpose | Example |
|---|---|---|
-h | Hostname or IP address | redis-cli -h 192.168.1.50 |
-p | Port number | redis-cli -p 6380 |
-a | Password (AUTH) | redis-cli -a mypassword |
-n | Database index | redis-cli -n 3 |
-r | Repeat a command N times | redis-cli -r 1000 PING |
-i | Interval between repeats (seconds) | redis-cli -r 5 -i 1 INFO |
Warning
Passwords on the Command Line
Using -a exposes the password in your shell history and process lists. Prefer the REDISCLI_AUTH environment variable or interactive authentication when security matters.
Example: Remote Connection
# Connect to a Redis instance on another machine
redis-cli -h redis.example.com -p 6379 -a "secure-pass" -n 2
# Or use an environment variable to hide the password
export REDISCLI_AUTH="secure-pass"
redis-cli -h redis.example.comInspecting the Server with INFO
The INFO command is your dashboard. It returns dozens of metrics about memory, clients, replication, and more.
# All sections
redis-cli INFO
# A specific section
redis-cli INFO memoryTypical output for INFO server:
# Server
redis_version:7.2.4
redis_mode:standalone
os:Linux 6.5.0
arch_bits:64
tcp_port:6379Two sections you should memorize early are:
INFO memory— Showsused_memory,used_memory_human, andmaxmemory. Watch these to avoid out-of-memory crashes.INFO stats— Showstotal_commands_processed,keyspace_hits,keyspace_misses. Use hits and misses to evaluate cache efficiency.
Monitoring Live Commands with MONITOR
MONITOR streams every command the server receives in real time. It is invaluable for debugging, but it carries a performance penalty—never leave it running on a production server under heavy load.
redis-cli MONITORSample output while another client runs GET name:
1704067200.123456 [0 127.0.0.1:54321] "GET" "name"Press Ctrl + C to stop monitoring.
Benchmarking with redis-benchmark
Redis ships with a built-in benchmark tool. It is useful for establishing a baseline on your hardware.
# Run the default benchmark: 50 parallel clients, 100000 requests
redis-benchmark
# Benchmark only SET and GET with 100 parallel clients
redis-benchmark -t set,get -c 100 -n 1000000
# Example output snippet
# SET: 120000.00 requests per second
# GET: 125000.00 requests per secondTip
Interpreting Results
Your laptop will not match production server numbers, and that is fine. Use redis-benchmark to compare before-and-after tuning (network settings, persistence configs) on the same machine, not to prove Redis is fast in general. That part is already well established.
The Configuration File
Redis behavior is controlled by redis.conf. On Linux, it usually lives at /etc/redis/redis.conf. On macOS with Homebrew, check /opt/homebrew/etc/redis.conf (Apple Silicon) or /usr/local/etc/redis.conf (Intel).
Key settings to know:
After editing the configuration file, restart the server for changes to take effect:
# Systemd-based Linux
sudo systemctl restart redis-server
# Homebrew on macOS
brew services restart redisStopping the Server
From redis-cli, you can gracefully shut down:
redis-cli SHUTDOWNOr send the signal directly:
# Find the process ID and terminate
pgrep redis-server | xargs killA graceful shutdown ensures that pending writes are flushed and persistence files are closed cleanly.
FAQ
Do I need to create a database or user before using Redis?
No. Redis has no concept of users or schemas out of the box (though Redis 6+ supports ACLs for access control). Connect and start setting keys immediately.
Why does redis-cli show 127.0.0.1:6379 instead of a file path?
Redis is a network server. It listens on a TCP port, not a local file socket (unless you configure a Unix socket). You can connect from the same machine or across a network.
What does (nil) mean in the CLI output?
It means the key does not exist. It is Redis's way of returning "nothing here."
Can I run multiple Redis servers on one machine?
Yes. Start each with a different port and configuration file:
redis-server --port 6380 --daemonize yes
redis-server --port 6381 --daemonize yesHow do I check if Redis is running after I close my terminal?
redis-cli pingIf it replies PONG, the server is still active. On Linux, sudo systemctl status redis-server confirms the service state.
Should I install Redis via Docker instead?
Docker is a valid option for local development:
docker run -d --name redis -p 6379:6379 redis:latestHowever, this chapter focuses on native installation so you understand the configuration files, service management, and logging locations that matter in production.