ScriptsApr 13, 2026·3 min read

Redis — The High-Performance In-Memory Data Store

Redis is the most popular in-memory data structure store. It serves as a database, cache, message broker, and streaming engine with support for strings, hashes, lists, sets, sorted sets, streams, and vector search — all with sub-millisecond latency.

SC
Script Depot · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

# Install Redis
# macOS
brew install redis && brew services start redis

# Linux
sudo apt install redis-server && sudo systemctl start redis

# Docker
docker run -d -p 6379:6379 redis:latest

# Connect and test
redis-cli
> SET greeting "Hello Redis"
> GET greeting
> INCR counter
> LPUSH queue "task1" "task2"

Introduction

Redis (Remote Dictionary Server) is the most widely used in-memory data store in the world. Originally created by Salvatore Sanfilippo in 2009, it provides blazing-fast data access with sub-millisecond latency, making it the go-to solution for caching, session management, real-time analytics, message queuing, and rate limiting.

With over 74,000 GitHub stars, Redis is used by virtually every major technology company. Its versatility as a cache, database, and message broker — combined with its simplicity and performance — has made it an essential component of modern application architectures.

What Redis Does

Redis stores data in memory as key-value pairs, but goes far beyond simple strings. It supports rich data structures — lists, sets, sorted sets, hashes, streams, and geospatial indexes — each with specialized commands. This makes Redis suitable for use cases ranging from simple caching to complex real-time applications.

Architecture Overview

[Clients]
redis-cli, application SDKs
(Python, Node.js, Java, Go...)
        |
   [Redis Server]
   Single-threaded event loop
   (I/O multiplexing)
        |
   [In-Memory Data Store]
   +-------+-------+-------+
   |       |       |       |
[Strings] [Lists]  [Sets]  [Hashes]
[Sorted   [Streams] [Geo]  [HyperLogLog]
 Sets]    [Bitmaps] [JSON]  [Vectors]
        |
   [Persistence]
   RDB snapshots + AOF log
        |
   [Clustering]
   Redis Cluster for
   horizontal scaling
   Redis Sentinel for HA

Self-Hosting & Configuration

# redis.conf — key configuration
# Memory
maxmemory 2gb
maxmemory-policy allkeys-lru

# Persistence
save 900 1      # RDB: save after 900s if 1+ keys changed
save 300 10     # save after 300s if 10+ keys changed
appendonly yes  # Enable AOF persistence

# Security
requirepass your-strong-password

# Network
bind 0.0.0.0
port 6379
# Python usage
import redis

r = redis.Redis(host="localhost", port=6379, decode_responses=True)

# Basic operations
r.set("user:1:name", "Alice", ex=3600)  # expires in 1 hour
name = r.get("user:1:name")

# Hash (like a mini-document)
r.hset("user:1", mapping={"name": "Alice", "email": "alice@example.com"})
user = r.hgetall("user:1")

# Sorted set (leaderboard)
r.zadd("scores", {"player1": 100, "player2": 250, "player3": 75})
top = r.zrevrange("scores", 0, 2, withscores=True)

# Pub/Sub
r.publish("notifications", "New order received")

Key Features

  • Sub-Millisecond Latency — in-memory storage with 100K+ ops/sec
  • Rich Data Structures — strings, lists, sets, sorted sets, hashes, streams
  • Persistence — RDB snapshots and AOF log for durability
  • Pub/Sub — real-time messaging between publishers and subscribers
  • Streams — append-only log for event sourcing and message queues
  • Clustering — horizontal scaling with automatic sharding
  • Lua Scripting — atomic server-side operations
  • Vector Search — built-in vector similarity search for AI applications

Comparison with Similar Tools

Feature Redis Memcached Valkey DragonflyDB KeyDB
Data Structures Rich Strings only Rich (Redis fork) Rich (Redis compat) Rich
Persistence Yes No Yes Yes Yes
Pub/Sub Yes No Yes Yes Yes
Clustering Yes Client-side Yes Single-node Yes
Multi-Threaded I/O threads Yes I/O threads Yes Yes
License RSALv2/SSPL BSD BSD BSL 1.1 BSD
Vector Search Yes No Yes No No

FAQ

Q: Redis vs Memcached — which should I use? A: Redis for almost all use cases. Memcached only if you need pure string caching with multi-threaded simplicity. Redis provides richer data structures, persistence, pub/sub, and clustering.

Q: What happened with the Redis license change? A: In 2024, Redis changed from BSD to RSALv2/SSPL dual license. This led to the Valkey fork (backed by Linux Foundation) as a fully open-source alternative. Both are actively maintained.

Q: How do I handle cache invalidation? A: Use TTL (expiration) for time-based invalidation, pub/sub for event-based invalidation, or the WATCH/MULTI/EXEC transaction pattern for optimistic locking.

Q: Can Redis be used as a primary database? A: Yes, with persistence enabled (RDB + AOF). Redis provides durability guarantees suitable for primary storage. However, for complex queries and relational data, a traditional database is better.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets