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.

bash
# Update package lists
sudo apt update
 
# Install Redis
sudo apt install redis-server -y
 
# Verify the installed version
redis-server --version

After installation, Redis usually starts automatically as a system service.

bash
# 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-server

Linux (RHEL / CentOS / Rocky Linux)

bash
# Install from EPEL or default repositories
sudo dnf install redis -y
 
# Start and enable the service
sudo systemctl start redis
sudo systemctl enable redis

macOS (Homebrew)

Homebrew is the most convenient path on macOS.

bash
# 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-server

Windows (WSL2)

Redis does not provide a native Windows server. Use WSL2 and follow the Linux instructions above.

bash
# Inside a WSL2 Ubuntu terminal
sudo apt update
sudo apt install redis-server -y
 
# Start the server
sudo service redis-server start

Tip

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

bash
# 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 yes

When the server starts successfully, you will see output similar to:

plaintext
[1] 01 Jan 2026 00:00:00.000 # Server initialized
[1] 01 Jan 2026 00:00:00.000 * Ready to accept connections tcp port: 6379

Port 6379 is the default Redis port.

Your First Ping

Open a second terminal window and run:

bash
redis-cli ping

If the server is running, it replies:

plaintext
PONG

That 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.

bash
redis-cli
plaintext
127.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.

FlagPurposeExample
-hHostname or IP addressredis-cli -h 192.168.1.50
-pPort numberredis-cli -p 6380
-aPassword (AUTH)redis-cli -a mypassword
-nDatabase indexredis-cli -n 3
-rRepeat a command N timesredis-cli -r 1000 PING
-iInterval 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

bash
# 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.com

Inspecting the Server with INFO

The INFO command is your dashboard. It returns dozens of metrics about memory, clients, replication, and more.

bash
# All sections
redis-cli INFO
 
# A specific section
redis-cli INFO memory

Typical output for INFO server:

plaintext
# Server
redis_version:7.2.4
redis_mode:standalone
os:Linux 6.5.0
arch_bits:64
tcp_port:6379

Two sections you should memorize early are:

  • INFO memory — Shows used_memory, used_memory_human, and maxmemory. Watch these to avoid out-of-memory crashes.
  • INFO stats — Shows total_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.

bash
redis-cli MONITOR

Sample output while another client runs GET name:

plaintext
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.

bash
# 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 second

Tip

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:

bash
# Systemd-based Linux
sudo systemctl restart redis-server
 
# Homebrew on macOS
brew services restart redis

Stopping the Server

From redis-cli, you can gracefully shut down:

bash
redis-cli SHUTDOWN

Or send the signal directly:

bash
# Find the process ID and terminate
pgrep redis-server | xargs kill

A 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:

bash
redis-server --port 6380 --daemonize yes
redis-server --port 6381 --daemonize yes

How do I check if Redis is running after I close my terminal?

bash
redis-cli ping

If 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:

bash
docker run -d --name redis -p 6379:6379 redis:latest

However, this chapter focuses on native installation so you understand the configuration files, service management, and logging locations that matter in production.