Learn Redis

In-memory data structure store for caching, queues, counters and real-time data

20 lessons · 4 hours · 4 levels · covers Redis 8.2

Redis keeps data structures such as strings, hashes, lists, sets, sorted sets and streams in memory and serves them with sub-millisecond latency. It is the standard choice for caching, sessions, rate limiting, leaderboards, queues and pub/sub, and can persist to disk and replicate for availability.

Before you start

Redis builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics7 lessons · 59 min in total
2. PracticalUse it productively at work, with the usual idioms13 lessons · 2 hours in total
3. AdvancedThe less common features, performance and trade-offs17 lessons · 3 hours in total
4. ExpertInternals and the edge cases experts know20 lessons · 4 hours in total

The Redis tree

RedisWhat Redis is and redis-cliWhat Redis is andredis-cliStrings and countersStrings and countersKeys, expiry and SCANKeys, expiry andSCANHashesHashesLists and simple queuesLists and simplequeuesSetsSetsSorted sets and leaderboardsSorted sets andleaderboardsCaching patternsCaching patternsRate limiting with countersRate limiting withcountersPipelining and clientsPipelining and clientsMULTI/EXEC and WATCHMULTI/EXEC andWATCHPub/Sub messagingPub/Sub messagingBitmaps and HyperLogLogBitmaps andHyperLogLog
Essentials and Practical shown (13 of 20 lessons); the full list is below. Click a lesson to read it.

All 20 lessons, in order

Getting started

  1. What Redis is and redis-cli · Essentials · 8 min

    Redis is an in-memory key-value server whose values are data structures, driven by simple commands.

  2. Keys, expiry and SCAN · Essentials · 9 min

    Manage keys with DEL, EXPIRE and TTL, understand how expiry works, and iterate the keyspace safely with SCAN.

Core data types

  1. Strings and counters · Essentials · 8 min

    Store text, numbers or binary blobs in string keys with SET and GET, and count atomically with INCR.

  2. Hashes · Essentials · 8 min

    Store objects as hashes of field-value pairs and read or update single fields with HSET, HGET and HINCRBY.

  3. Lists and simple queues · Essentials · 9 min

    Use lists as stacks, queues and capped logs with LPUSH, RPOP, LRANGE, LTRIM and blocking pops.

  4. Sets · Essentials · 7 min

    Store unique unordered members with SADD and test membership, intersect and union sets on the server.

  5. Sorted sets and leaderboards · Essentials · 10 min

    Keep members ordered by a numeric score with ZADD and query by rank or score range for leaderboards and timelines.

  6. Bitmaps and HyperLogLog · Practical · 10 min

    Count and flag huge numbers of items in tiny memory with bitmaps (SETBIT, BITCOUNT) and HyperLogLog (PFADD, PFCOUNT).

Application patterns

  1. Caching patterns · Practical · 12 min

    Apply cache-aside with TTLs, choose invalidation strategies and protect the database from stampedes.

  2. Rate limiting with counters · Practical · 10 min

    Build fixed-window and sliding-window rate limiters with INCR, EXPIRE and sorted sets.

Pipelines, transactions and scripts

  1. Pipelining and clients · Practical · 9 min

    Batch many commands per network round trip with pipelines and use client libraries with connection pools.

  2. MULTI/EXEC and WATCH · Practical · 11 min

    Group commands to run atomically with MULTI/EXEC and use WATCH for optimistic check-and-set.

  3. Lua scripts and functions · Advanced · 14 min

    Run logic atomically on the server with EVAL and Redis Functions, passing keys and arguments correctly.

Messaging and streams

  1. Pub/Sub messaging · Practical · 9 min

    Broadcast messages to subscribers on channels and patterns with PUBLISH and SUBSCRIBE, knowing its fire-and-forget limits.

  2. Streams and consumer groups · Advanced · 15 min

    Append events to a stream with XADD and process them reliably with consumer groups, acknowledgements and claiming.

Persistence and memory

  1. Persistence: RDB and AOF · Advanced · 12 min

    Choose between RDB snapshots and the append-only file, and understand what data you can lose on a crash.

  2. Memory limits and eviction · Advanced · 12 min

    Cap memory with maxmemory, pick an eviction policy, and find what is using memory.

Replication, cluster and internals

  1. Replication and Sentinel · Expert · 14 min

    Replicate a primary to replicas asynchronously and use Sentinel for automatic failover, knowing what can be lost.

  2. Redis Cluster and hash slots · Expert · 14 min

    Shard data across nodes with 16384 hash slots, use hash tags for multi-key operations and handle redirections.

  3. Event loop, encodings and latency · Expert · 14 min

    Understand the single-threaded event loop, I/O threads, compact encodings and the causes of latency spikes.