Skip to content

2. Installation & Configuration

Linux Installation (Ubuntu example)

bash
# Method 1: Install via package manager
sudo apt update
sudo apt install redis-server

# Start Redis service
sudo systemctl start redis-server

# Enable auto-start on boot
sudo systemctl enable redis-server

# Verify installation
redis-cli ping
bash
PONG
bash
# Method 2: Build from source (recommended for latest version)
wget https://download.redis.io/releases/redis-7.2.4.tar.gz
tar xzf redis-7.2.4.tar.gz
cd redis-7.2.4
make
sudo make install

# Start server
redis-server --daemonize yes

macOS Installation

bash
# Using Homebrew
brew install redis

# Start service
brew services start redis

# Or run in foreground to see logs
redis-server

Windows Installation

📝 Note: Redis officially does not support Windows, but you can use the following options:

  • 🐳 Docker (Recommended): docker run -p 6379:6379 redis:7.2
  • 🐧 WSL2: Install the Linux way inside Windows Subsystem for Linux
bash
# Docker method (simplest)
docker run -d --name redis -p 6379:6379 redis:7.2

# Enter Redis CLI
docker exec -it redis redis-cli

Common redis.conf Settings

bash
# redis.conf key configuration items

# === Network ===
bind 127.0.0.1          # Bind address, bind to internal IP in production
port 6379               # Listening port
protected-mode yes      # Protection mode, set to no for external access and configure password
tcp-backlog 511         # TCP connection queue length
timeout 0               # Client idle timeout (seconds), 0 means never timeout

# === Security ===
requirepass your_strong_password  # Set access password
rename-command FLUSHALL ""        # Disable dangerous commands

# === Memory ===
maxmemory 2gb                   # Maximum memory limit
maxmemory-policy allkeys-lru    # Memory eviction policy

# === Persistence ===
save 900 1              # Trigger RDB if at least 1 write in 900 seconds
save 300 10
save 60 10000
appendonly yes           # Enable AOF
appendfsync everysec     # AOF sync policy

# === Logging ===
loglevel notice          # Log level: debug/verbose/notice/warning
logfile "/var/log/redis/redis-server.log"

💡 Tip: After modifying configuration, you need to restart Redis or run CONFIG SET parameter value for hot reload. Use CONFIG REWRITE to persist runtime changes to the configuration file.