
Redis: how it works and when it makes an application faster
Learn how Redis works through caching examples, data structures, benchmarks and practical trade-offs.
What Redis does
A product page may ask a database for the same information thousands of times. When data changes infrequently, a cache can keep a temporary copy close to the application and avoid repeated database work. Redis is an in-memory data structure server commonly used for this purpose, as well as sessions, counters, queues and other shared state.
An application sends commands over the network. Redis stores values under keys, supports expiration and offers atomic operations. Memory access is fast, but the complete request also includes network and application costs.
Keys, values and data structures
A key is an address for a value. In redis-cli, a product can be stored for five minutes:
SET product:42 "Wireless keyboard" EX 300
GET product:42
TTL product:42GET reads the value and TTL shows the remaining lifetime. Besides strings, Redis supports hashes, lists, sets, sorted sets and streams. A sorted set can maintain a leaderboard without having the application sort the entire collection on every request:
ZADD leaderboard 1200 player:anna 1450 player:oleh
ZREVRANGE leaderboard 0 9 WITHSCORESThe second command returns up to ten highest-scoring players. Check command complexity and latency as collections grow.
A product-page cache
With cache-aside, the application first asks Redis for the product. On a hit, it returns the cached result. On a miss, it reads the primary database, stores the result with a TTL and returns it. When the product changes, deleting the key lets a later request refill it. TTL limits staleness but concurrent reads and writes can still race.
Suppose a product receives 1,000 requests in a minute and 999 are cache hits: the primary database avoids most repeated reads. This is an illustration, not a measured result. The actual hit rate depends on traffic, expiry, updates and available memory.
When a popular key expires, many requests may miss simultaneously and overload the database: a cache stampede. Depending on freshness requirements, limit concurrent refreshes or temporarily serve a previous value while refreshing.
Redis also stores sessions and shared rate-limit counters. INCR is atomic, but combining an increment and expiry requires an atomic operation such as a Lua script; the process can otherwise stop between the two commands.
Reading performance numbers
In a Lavik benchmark dated 21 October 2026, Redis 8.10.2 reached roughly 976,000 GET/s and 864,000 SET/s at 1,280 connections. The test used a 16-vCPU VM, ten million 1-KiB values, pipeline 1 and 16 I/O threads; AOF and scheduled snapshots were disabled. Lavik is a competing vendor, and the measurements describe that setup rather than a guarantee. [1]
Throughput and latency answer different questions. At that GET point p99.9 was 7.039 ms: approximately 99.9% of operations completed within that threshold. Concurrency can increase throughput while also increasing queueing delay. Measure the full application request and database load, not just GET speed.
On an isolated test server, a synthetic baseline can be run with:
redis-benchmark -h 127.0.0.1 -p 6379 -t get,set -n 100000 -c 50 -d 1024 -P 1This uses 50 connections and 1,024-byte values. It does not reproduce your key distribution, command mix or production network.
Memory, persistence and licensing
Data consumes RAM plus metadata and fragmentation. Set a memory budget and an eviction policy appropriate to the data: losing a cache entry is different from losing a session or a queued job. Restrict network access and configure authentication and TLS where needed.
RDB snapshots capture a point in time; changes since the last snapshot can be lost in a failure. AOF records operations, with the loss window depending on disk synchronization settings. The approaches can be combined, and replicas do not replace tested backups.
Redis Open Source 8 and later offer a choice of RSALv2, SSPLv1 or AGPLv3; Redis 7.2 and earlier retain BSD-3-Clause. Check the applicable terms for the version and use case. [2] Start with the slow part of your system and the freshness your users need before adding a cache.
Where Redis fits in real products
Sessions across API servers
After login the application issues an opaque random session ID in a secure cookie and stores the associated session in Redis with a TTL. Any API instance can look up that ID. Logout deletes the key; cookie security, ID rotation and authorization remain application responsibilities. Losing sessions may force users to log in again, so decide whether persistence and replicas are appropriate.
Browser → API 1 → SET session:<id> … EX 1800
Browser → API 2 → GET session:<id> → user
Logout → API → DEL session:<id>Rate limits and messages
A shared counter lets multiple instances enforce one limit. INCR is atomic, but increment and expiry must be combined atomically, for example in a Lua script. A fixed window can allow a burst across its boundary; sliding windows and token buckets behave differently. Decide whether an outage should fail open, fail closed or use a local fallback.
Pub/Sub delivers to connected subscribers and does not replay missed messages. Streams retain entries and support consumer groups and acknowledgments; configure retention, pending-message recovery, persistence and idempotent consumers. Streams alone do not guarantee exactly-once business effects. [4] [5]
What happens after SET
The client sends a command over the network; Redis updates its in-memory data and responds. Depending on configuration, AOF records operations and RDB creates point-in-time snapshots. A client response is not automatically a promise that the write is already durable on disk. [6]
API → SET → Redis memory → API response
├─ RDB snapshots
├─ AOF operation log
└─ replicaThis diagram identifies roles, not a guaranteed synchronization order. Replication is generally asynchronous, so a replica may lag. Test recovery from backups rather than treating a replica as a backup.
What happens after SET
Section redis-memory-model screenshotSources
Related Articles

Redis vs Valkey: performance, trade-offs and choosing for your project
Compare Redis and Valkey by benchmarks, licensing, features and migration costs.

Valkey: how the key–value store works and where to use it
An introduction to Valkey, shared state, caching, performance and migration from Redis.