Redis Installation
Installing Redis takes just a few minutes. Once it runs, you talk to it through a command-line tool called redis-cli. This topic walks you through installation on the three main operating systems and shows you your first real Redis commands.
How Redis Works at a High Level
Redis runs as a server process on your machine. Your app (or you, through the terminal) sends commands to that server, and the server responds. Think of it like calling a restaurant on the phone — you place your order, they prepare it, and they read the result back to you.
┌─────────────────────────────────────────────────────┐ │ Your Machine │ │ │ │ ┌─────────────┐ commands ┌─────────────────┐ │ │ │ redis-cli │─────────────▶│ Redis Server │ │ │ │ (your │ │ (listens on │ │ │ │ terminal) │◀─────────────│ port 6379) │ │ │ └─────────────┘ responses └─────────────────┘ │ │ │ └─────────────────────────────────────────────────────┘
Installing Redis
On Linux (Ubuntu/Debian)
Open your terminal and run these two commands one after the other:
sudo apt update sudo apt install redis-server
Redis starts automatically after installation. Confirm it is running:
redis-cli ping
You should see PONG as the reply. That means Redis is alive and listening.
On macOS
Use Homebrew. If you do not have Homebrew, install it from brew.sh first. Then run:
brew install redis brew services start redis
Test it the same way:
redis-cli ping
On Windows
The official Redis project recommends using Windows Subsystem for Linux (WSL2). Install WSL2 from Microsoft's documentation, then follow the Linux steps above inside WSL2.
Alternatively, download a Windows-compatible build from the tporadowski/redis GitHub releases page. Unzip it, run redis-server.exe, then redis-cli.exe.
Opening the Redis Command Line
Once Redis is running, open the interactive shell:
redis-cli
Your prompt changes to show the server address:
127.0.0.1:6379>
You are now connected. Every command you type here goes straight to Redis.
Your First Five Commands
1. SET – Store a Value
127.0.0.1:6379> SET city "Mumbai" OK
You stored the text Mumbai under the key named city.
2. GET – Retrieve a Value
127.0.0.1:6379> GET city "Mumbai"
3. DEL – Delete a Key
127.0.0.1:6379> DEL city (integer) 1
The number 1 means one key was deleted. Run GET again and you get nil — the key is gone.
4. EXISTS – Check if a Key Exists
127.0.0.1:6379> SET username "Alice" OK 127.0.0.1:6379> EXISTS username (integer) 1 127.0.0.1:6379> EXISTS password (integer) 0
1 means the key exists. 0 means it does not.
5. KEYS – List All Keys
127.0.0.1:6379> KEYS * 1) "username"
The asterisk is a wildcard that matches everything. Use this only in development — on a large production database with millions of keys, KEYS * blocks the server and slows everything down.
Diagram – What Happens When You Run SET and GET
You type: SET username "Alice"
│
▼
Redis stores in memory:
┌─────────────────────────┐
│ Key: username │
│ Value: "Alice" │
└─────────────────────────┘
│
You type: GET username
│
▼
Redis reads from memory:
──────────────────────────
Returns: "Alice"
Key Points
- Redis runs as a server and listens on port 6379 by default.
- You interact with Redis using redis-cli from the terminal.
- SET stores a key-value pair; GET retrieves it; DEL removes it.
- EXISTS returns 1 if a key is present and 0 if it is not.
- Avoid KEYS * on production servers with large datasets.
