Features
- In-memory key-value store with sub-millisecond latency
- Rich data structures (strings, hashes, lists, sets, sorted sets)
- Pub/Sub and Streams for messaging
- Lua scripting and Redis Functions
Pros
- Unmatched speed for caching and session storage
- Versatile data structures beyond simple key-value
- Excellent for rate limiting, queues, and leaderboards
Cons
- Data size limited by available memory
- Persistence options trade off durability vs performance
- Recent license change from BSD to dual-license
Overview
Redis is an in-memory data structure store used as a cache, message broker, session store, and real-time data platform. Its sub-millisecond latency and rich set of data structures make it the go-to solution for performance-critical data operations.
Beyond simple caching, Redis supports sorted sets for leaderboards, pub/sub for real-time messaging, streams for event sourcing, and geospatial indexes for location queries. Redis Stack adds JSON, search, time series, and graph capabilities on top of the core engine.
When to Use
Use Redis for caching frequently accessed data, managing user sessions, implementing rate limiting, building real-time features (chat, notifications), job queues, and leaderboards. It’s a complement to your primary database, not a replacement.
Getting Started
docker run -d --name redis -p 6379:6379 redis:7
npm install redis
import { createClient } from "redis";
const client = createClient();
await client.connect();
await client.set("user:1:name", "Alice");
const name = await client.get("user:1:name");