Redis: Complete Course
Master Redis from core data structures to production-grade patterns like caching, pub/sub, and distributed locks. By the end, you will build a real-time leaderboard and session-management system backed entirely by Redis.
Course Content
6 modules · 30 lessonsRedis Fundamentals
Understand what Redis is, install it, and run your first commands against a live server.
What is Redis and why use it instead of a database
in-memory data store, key-value model, Redis vs relational DB, Redis vs Memcached, use cases, persistence overview
How to install Redis on Linux, macOS, and Docker
apt install, Homebrew install, Docker run, redis-server, redis-cli, default port 6379, config file location
Redis data types overview: strings, hashes, lists, sets, sorted sets
string type, hash type, list type, set type, sorted set type, TYPE command, choosing the right type
Redis key expiry and TTL: how to set and check expiration
EXPIRE, EXPIREAT, TTL, PERSIST, key eviction, expiry use cases, EX option on SET
Redis persistence: RDB snapshots vs AOF logging explained
RDB snapshot, AOF append-only file, BGSAVE, AOF rewrite, durability tradeoffs, redis.conf persistence settings, no persistence mode
Core Commands and Data Structures
Write production-ready commands against every major Redis data type and understand their time complexities.
Redis String commands: SET, GET, INCR, APPEND, GETRANGE
SET options NX EX PX, GET, MSET MGET, INCR INCRBY DECR, APPEND, GETRANGE, STRLEN, atomic counter pattern
Redis Hash commands: HSET, HGET, HMGET, HDEL, HGETALL
HSET multiple fields, HGET, HMGET, HGETALL, HDEL, HEXISTS, HLEN, HINCRBY, hash vs string tradeoffs
Redis List commands: LPUSH, RPUSH, LPOP, LRANGE, LLEN
LPUSH RPUSH, LPOP RPOP, LRANGE, LLEN, LINDEX, LSET, LTRIM, blocking BLPOP, queue vs stack pattern
Redis Set commands: SADD, SMEMBERS, SINTER, SUNION, SDIFF
SADD SREM, SMEMBERS SCARD, SISMEMBER, SINTER SUNION SDIFF, SMOVE, unique visitor tracking, tag systems
Redis Sorted Set commands: ZADD, ZRANGE, ZRANK, ZSCORE, ZRANGEBYSCORE
ZADD options NX XX GT LT, ZRANGE ZREVRANGE, ZRANK ZREVRANK, ZSCORE, ZRANGEBYSCORE, ZREM, ZINCRBY, leaderboard pattern
Caching Patterns
Implement the industry-standard caching strategies that power high-traffic production systems.
Cache-aside pattern: how to implement read-through caching in Node.js
cache-aside pattern, cache miss, cache hit, read-through vs write-through, TTL strategy, cache stampede risk, stale data tradeoff
Write-through and write-behind caching: when to update Redis on writes
write-through pattern, write-behind pattern, consistency tradeoff, dual write, cache invalidation, write amplification
Cache invalidation strategies: TTL, event-based, and tag-based invalidation
TTL-based invalidation, explicit delete on write, tag-based invalidation, cache key namespacing, versioned cache keys, invalidation fan-out problem
Redis cache eviction policies: LRU, LFU, and allkeys explained
maxmemory config, allkeys-lru, volatile-lru, allkeys-lfu, volatile-lfu, noeviction, allkeys-random, choosing eviction policy
Preventing cache stampede with Redis locks and probabilistic early expiration
cache stampede definition, mutex lock with SET NX, lock timeout, probabilistic early expiration algorithm, XFetch formula, dog-pile effect
Pub/Sub and Streams
Build real-time messaging features and durable event streams using Redis Pub/Sub and Redis Streams.
Redis Pub/Sub: how PUBLISH and SUBSCRIBE work
PUBLISH command, SUBSCRIBE command, channel model, fire-and-forget semantics, no message persistence, multiple subscribers, PSUBSCRIBE pattern matching
Redis Streams introduction: durable append-only event logs
XADD command, stream entry ID, XLEN, XRANGE, XREAD, auto-generated IDs, stream as event log, difference from Pub/Sub
Redis Stream consumer groups: reliable message processing with XACK
XGROUP CREATE, XREADGROUP, XACK, pending entries list, consumer group semantics, at-least-once delivery, XCLAIM for stuck messages
Keyspace notifications: subscribe to Redis events like key expiry
keyspace notifications config, notify-keyspace-events, KEA flags, expired event, set event, del event, use cases for expiry hooks
When to use Pub/Sub vs Streams vs a job queue in Redis
Pub/Sub vs Streams decision criteria, message durability, fan-out delivery, consumer groups, BullMQ and Redis Lists as queues, at-most-once vs at-least-once
Transactions, Scripting, and Pipelines
Execute atomic operations, reduce round trips with pipelines, and extend Redis with server-side Lua scripts.
Redis transactions with MULTI and EXEC: atomic command batches
MULTI, EXEC, DISCARD, command queuing, all-or-nothing execution, error handling in transactions, no rollback on runtime errors
WATCH and optimistic locking in Redis: how to handle concurrent updates
WATCH command, optimistic locking, CAS pattern, MULTI after WATCH, EXEC returning nil on conflict, retry loop, WATCH vs pessimistic locking
Redis pipelines: batch commands to reduce network round trips
pipeline concept, round trip time, pipelining vs transactions, pipeline in Node.js, pipeline in Python, when to use pipelines, throughput benchmark
Lua scripting in Redis: run server-side logic atomically with EVAL
EVAL command, KEYS and ARGV, atomicity of Lua scripts, no interleaving, redis.call vs redis.pcall, SCRIPT LOAD EVALSHA, when to use Lua
Rate limiting with Redis: sliding window and token bucket patterns
rate limiting use case, fixed window counter, sliding window log with Sorted Set, token bucket with INCR and TTL, MULTI/EXEC for atomicity, rate limit headers
Redis in Production
Deploy, scale, monitor, and secure Redis using replication, Sentinel, Cluster, and observability tooling.
Redis replication: primary-replica setup and how replication works
primary-replica architecture, REPLICAOF command, full resync, partial resync, replication offset, read scaling with replicas, replication lag, async replication caveat
Redis Sentinel: automatic failover and high availability explained
Sentinel process, quorum, leader election, failover process, client reconfiguration, sentinel.conf, minimum 3 sentinels rule
Redis Cluster: horizontal sharding and how data is distributed
hash slot concept, 16384 slots, CRC16 key hashing, node assignment, CLUSTER INFO, hash tags, MOVED redirect, ASK redirect, minimum 3 primary nodes
Redis security: authentication, TLS, and ACL user permissions
requirepass, AUTH command, ACL LIST, ACL SETUSER, channel permissions, key pattern permissions, TLS configuration, binding to localhost, RENAME-COMMAND
Monitoring Redis with INFO, MONITOR, SLOWLOG, and latency commands
INFO sections, DBSIZE, MONITOR command, SLOWLOG GET, slowlog-log-slower-than, LATENCY HISTORY, memory usage analysis, redis-cli --stat, OBJECT FREQ for LFU
