Redis, short for Remote Dictionary Server, is an open-source, in-memory data structure store used as a database, cache, and message broker. Created by Salvatore Sanfilippo in 2009, Redis supports data structures such as strings, hashes, lists, sets, sorted sets, bitmaps, and hyperloglogs. It is widely used for caching, session management, real-time analytics, and pub/sub messaging. Installation can be performed via system package managers (apt install redis-server on Debian/Ubuntu, yum install redis on RHEL/CentOS) or from the official site at Redis Official Downloads.
Redis exists to provide extremely fast, reliable, and flexible data storage for applications requiring low-latency access. Its design emphasizes simplicity, performance, and atomic operations, allowing developers to implement high-throughput, scalable solutions while maintaining data integrity.
Redis: Basic Operations
Redis supports common operations for data manipulation including SET, GET, DEL, and EXPIRE.
# Start Redis CLI
redis-cli
# Set a key
SET mykey "Hello, Redis!"
# Get the value
GET mykey
# Set a key with expiration
SETEX session_token 3600 "abc123"These commands allow storing and retrieving values with optional time-to-live (TTL) for cache management.
Redis: Data Structures
Redis offers rich data types to handle complex application scenarios.
# List operations
LPUSH tasks "task1"
RPUSH tasks "task2"
LRANGE tasks 0 -1
# Hash operations
HSET user:1001 name "Alice" age 30
HGETALL user:1001
# Set operations
SADD online_users user1 user2
SMEMBERS online_usersThese structures enable fast access and manipulation, supporting use cases from leaderboards to real-time analytics.
Redis: Pub/Sub and Messaging
Redis provides a publish/subscribe messaging system for real-time communication between processes.
# Subscribe to a channel
SUBSCRIBE updates
# Publish a message
PUBLISH updates "New data available"This allows event-driven architectures and distributed systems to communicate efficiently.
Redis: Persistence
Redis supports snapshots and append-only file (AOF) persistence to maintain durability alongside in-memory speed.
# Enable AOF in redis.conf
appendonly yes
appendfilename "appendonly.aof"Persistence ensures that data survives server restarts while still benefiting from rapid memory access.
Redis is commonly used in caching layers, real-time analytics, session stores, message brokering, and queueing systems. It integrates well with other technologies such as Grafana, Varnish, and Prometheus to provide robust monitoring, observability, and high-performance application architectures.