RedisCacheDatabase7 min read

Install and configure Redis

Install Redis as a cache and in-memory data store to improve your application performance.


Redis is an in-memory data store that works as a cache, message broker, and key-value database. It significantly improves application performance.

Step 1 — Install Redis

bash
sudo apt update
sudo apt install redis-server -y

Step 2 — Configure Redis

Edit the configuration file:

bash
sudo nano /etc/redis/redis.conf

Change these directives:

terminal
# Listen only on localhost (security)
bind 127.0.0.1 ::1

# Enable as systemd service
supervised systemd

# Set password
requirepass YourSecurePassword123

# Configure RDB persistence
save 900 1
save 300 10
save 60 10000

Step 3 — Restart and enable

bash
sudo systemctl restart redis-server
sudo systemctl enable redis-server
sudo systemctl status redis-server

Step 4 — Test the connection

bash
redis-cli
AUTH YourSecurePassword123
PING
# Response: PONG

Step 5 — Basic redis-cli operations

bash
# Store a value
SET myapp:config:version "1.0.0"

# Get a value
GET myapp:config:version

# Set with expiration (60 seconds)
SETEX session:abc123 60 "session-data"

# List all keys
KEYS *

# Server information
INFO memory

Step 6 — Configure memory limit

In /etc/redis/redis.conf:

terminal
maxmemory 256mb
maxmemory-policy allkeys-lru

Restart Redis after any configuration change.

Verify it works

bash
redis-cli -a YourSecurePassword123 INFO server | grep redis_version

Redis is ready to use as a session cache, job queue, or fast data store on your Baires Host VPS.


Was this guide helpful?