Redis
GitHub Overview
redis/node-redis
Redis Node.js client
Topics
Star History
Library
Redis
Overview
Redis stands for "REmote DIctionary Server" and is a high-performance in-memory data structure store. Used as cache, database, and message broker, it provides sub-millisecond response times, rich data structures, horizontal scaling, and publish/subscribe functionality. As of 2025, Redis has established its position as the absolute standard for distributed cache solutions, with managed services provided by all cloud providers including AWS, Azure, and GCP.
Details
Redis 8.0 was released in Spring 2025, significantly enhancing AI-focused features. Added Redis LangCache (semantic caching service for LLM apps), Vector Sets (new data type for vector embeddings), and native LangGraph integration. Adopted triple-license system with AGPL in addition to RSALv2/SSPL. Supports over 20 data types and efficiently processes diverse data structures including strings, lists, sets, sorted sets, hashes, and streams. Auto Tiering with Flash automatically moves less frequently accessed data to flash storage, dramatically improving memory efficiency.
Key Features
- Sub-millisecond Response: Extremely fast read/write performance through memory-based access
- Rich Data Structures: Flexible data modeling with 20+ data types
- Distributed Architecture: Supports sharding, clustering, and replication
- Publish/Subscribe: Real-time messaging functionality
- Persistence Options: Data protection through RDB snapshots and AOF logs
- AI/ML Integration: Vector Sets, semantic caching, LangGraph connectivity
Pros and Cons
Pros
- Overwhelming track record and reliability in distributed caching (10+ years of operation)
- Managed services available on all cloud providers
- Rich client libraries (Python, Java, Node.js, C#, etc.)
- Real-time applications and Edge Computing support
- Robustness through high availability and failover functionality
- Transparency and community support through open source
Cons
- Bottlenecks during high concurrent connections due to single-threaded design
- Memory usage proportional to data size (cost considerations)
- Complex configuration and tuning required (enterprise environments)
- Commercial usage constraints due to license changes
- High learning curve (complexity due to rich features)
- Need for performance optimization through proper data type selection
Reference Pages
Code Examples
Installation and Setup
# Launch with Docker
docker run --name redis-cache -p 6379:6379 -d redis:8.0
# Connection test with Redis CLI
redis-cli ping
# PONG
# Installation on Ubuntu/Debian
sudo apt update
sudo apt install redis-server
# Installation on CentOS/RHEL
sudo yum install epel-release
sudo yum install redis
Basic Cache Operations
# Basic string operations
SET user:1:name "John"
GET user:1:name
# "John"
# Cache with TTL (expiration)
SETEX session:abc123 3600 "user_data"
TTL session:abc123
# 3599
# Bulk operations with multiple keys
MSET user:1:email "[email protected]" user:1:age "25"
MGET user:1:name user:1:email user:1:age
# 1) "John"
# 2) "[email protected]"
# 3) "25"
# Key existence check and deletion
EXISTS user:1:name
# 1
DEL user:1:name
EXISTS user:1:name
# 0
Object Caching with Hashes
# Store user information as hash
HMSET user:2 name "Jane" email "[email protected]" age 28 status "active"
HGET user:2 name
# "Jane"
# Update specific hash fields
HSET user:2 last_login "2025-06-21 10:30:00"
HINCRBY user:2 login_count 1
# Retrieve entire hash
HGETALL user:2
# 1) "name"
# 2) "Jane"
# 3) "email"
# 4) "[email protected]"
# 5) "age"
# 6) "28"
# 7) "status"
# 8) "active"
# 9) "last_login"
# 10) "2025-06-21 10:30:00"
# 11) "login_count"
# 12) "1"
# Delete hash field
HDEL user:2 status
Queues and Stacks with Lists
# Use as queue (FIFO)
LPUSH task_queue "process_payment"
LPUSH task_queue "send_email"
LPUSH task_queue "update_inventory"
# Pop task from queue
RPOP task_queue
# "process_payment"
# Use as stack (LIFO)
LPUSH recent_items "item3"
LPUSH recent_items "item2"
LPUSH recent_items "item1"
LPOP recent_items
# "item1"
# Blocking POP (useful for task queues)
BLPOP task_queue 0 # infinite wait
Uniqueness Management with Sets
# User tag management
SADD user:1:tags "developer" "python" "redis"
SADD user:2:tags "designer" "photoshop" "redis"
# Find common tags
SINTER user:1:tags user:2:tags
# 1) "redis"
# Get all tags
SMEMBERS user:1:tags
# 1) "developer"
# 2) "python"
# 3) "redis"
# Check tag existence
SISMEMBER user:1:tags "python"
# 1
# Online user management
SADD online_users "user:1" "user:2" "user:3"
SCARD online_users
# 3
Rankings with Sorted Sets
# Create leaderboard
ZADD leaderboard 1500 "player1"
ZADD leaderboard 2100 "player2"
ZADD leaderboard 1800 "player3"
# Display ranking (descending order)
ZREVRANGE leaderboard 0 2 WITHSCORES
# 1) "player2"
# 2) "2100"
# 3) "player3"
# 4) "1800"
# 5) "player1"
# 6) "1500"
# Score range search
ZRANGEBYSCORE leaderboard 1600 2000
# 1) "player3"
# Get rank
ZREVRANK leaderboard "player2"
# 0
Publish/Subscribe
# Terminal 1: Subscriber
SUBSCRIBE notifications user_alerts
# Reading messages...
# Terminal 2: Publisher
PUBLISH notifications "System maintenance started"
# (integer) 1
PUBLISH user_alerts "You have new messages"
# (integer) 1
# Pattern matching subscription
PSUBSCRIBE user:*:notifications
PUBLISH user:123:notifications "Personal notification"
Redis Cluster and Scaling
# Check cluster information
CLUSTER INFO
CLUSTER NODES
# Hash tags for sharding
SET user:{1000}:profile "profile_data"
SET user:{1000}:preferences "pref_data"
# Placed in the same hash slot
# Replication configuration
# redis.conf
# replicaof 192.168.1.100 6379
# Check failover
INFO replication