Docs / Databases / Redis Caching Fundamentals

Redis Caching Fundamentals

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 26 views · 1 min read

What is Redis?

Redis is an in-memory data store used as a cache, session store, message broker, and more. It is extremely fast because all data lives in RAM, with optional persistence to disk.

Installation

sudo apt update
sudo apt install -y redis-server

Configuration

Edit /etc/redis/redis.conf:

# Bind to localhost only (security)
bind 127.0.0.1 ::1

# Set a password
requirepass your_redis_password

# Set max memory (e.g., 256 MB)
maxmemory 256mb
maxmemory-policy allkeys-lru
sudo systemctl restart redis-server

Basic Operations

# Connect
redis-cli -a your_redis_password

# String operations
SET mykey "hello"
GET mykey
SET session:abc123 "user_data" EX 3600  # Expires in 1 hour

# Check memory usage
INFO memory

# Monitor commands in real time
MONITOR

Common Use Cases

  • Page caching — cache rendered HTML pages
  • Session storage — faster than file-based sessions
  • Rate limiting — track request counts per IP
  • Queue — LPUSH/BRPOP for simple job queues

Memory Policies

  • allkeys-lru — evict least recently used keys (best for caching)
  • volatile-lru — evict LRU keys that have an expiry set
  • noeviction — return errors when memory is full

Was this article helpful?