Advanced Redis: streams, replication and security
You will build queue, ranking and approximate-counting patterns in Redis and learn to monitor and configure it securely.
Level 301 · 22 lessons · 18 practice labs
Lessons
Data structure patterns
- Job queues with lists: LPUSH, BRPOP and LMOVE: You will connect a producer and a consumer through a list and build a reliable queue that waits when empty.
- Sets: union, intersection and difference: You will compare two sets with SUNION, SINTER and SDIFF to find shared and differing members.
- Ranking lists and range queries with sorted sets: You will query the top N entries, a member’s rank and a score range with ZRANGE and ZRANK.
- Storing sessions and objects in hashes: You will keep session data in a hash, update a single field and give the session a lifetime.
- Approximate counting with HyperLogLog and bitmaps: You will count millions of unique visitors or daily active users using very little memory.
- Redis Streams and consumer groups: You will append events to a stream, let a group of workers share the reading and acknowledge processed entries.
- Short task: an app’s activity feed and counters
Behaviour and patterns
- Transactions with MULTI, EXEC and WATCH: You will run several commands as one uninterrupted block and abort if someone else changed the data.
- Messaging with Pub/Sub: You will publish and subscribe to a channel, knowing that Pub/Sub does not store messages.
- Atomic operations with Lua scripts (EVAL): You will write and load a small Lua script that runs several steps as one unit on the server.
- Rate limiting pattern: INCR, EXPIRE and Lua: You will build a counter that limits how many requests a user can make per minute without race conditions.
- Short task: atomic stock reduction with Lua
Operations
- Tuning RDB and AOF persistence: You will choose and tune RDB snapshots and the AOF log according to the balance of data loss and speed.
- Replication and failover with Sentinel: You will set up a replica Redis and see Sentinel promote it when the primary goes down.
- When memory fills: eviction policies and big keys: You will know the maxmemory-policy options and find the biggest memory consumers with MEMORY USAGE and --bigkeys.
- Monitoring with INFO, SLOWLOG and latency tools: You will read INFO output, find slow commands with SLOWLOG and monitor server health.
- Short task: a memory and persistence health check
Security
- Never leaving Redis exposed: bind and protected-mode: You will check whether your own Redis is reachable from outside and close it with bind and protected-mode.
- Users and command permissions with ACL: You will give each application its own account limited to its key prefix and the commands it needs, using Redis ACL.
- Encrypted connections with TLS in Redis: You will enable TLS on a Redis server and make redis-cli and an application connect encrypted.
- Restricting dangerous commands and a Redis hardening checklist: You will restrict commands like FLUSHALL, CONFIG and DEBUG with ACL and audit all security settings in one checklist.
- Capstone: make an exposed Redis safe and resilient
Practice labs
- Write events to an activity stream: Write user actions to a stream with XADD and read recent events with XRANGE.
- Share work with a consumer group: Share order events between two workers with a consumer group and verify each event is handled once.
- Claim pending messages from a crashed consumer: Find messages a crashed worker never acknowledged with XPENDING and hand them to another worker with XAUTOCLAIM.
- Mark daily logins with a bitmap: Track whether each user logged in today with a bitmap and count with BITCOUNT.
- Fetch listings in a price range with a sorted set: Keep property listings in a sorted set by price and return those in a range with paging.
- Compute weekly active users with bit operations: Combine seven daily bitmaps with BITOP and count users who came every day and at least one day.
- Run two commands together with MULTI: Make a points transfer that debits one account and credits another a single unit with MULTI/EXEC.
- Prevent a race with WATCH: Convert booking code that sells one seat twice to optimistic locking with WATCH and test it concurrently.
- Broadcast live notifications with Pub/Sub: Build a setup that publishes price changes to a channel for connected clients and show what a disconnected client misses.
- Run a simple Lua script: Write a short EVAL script that reads a counter and increments it only if it is under a limit.
- Put a per-minute request limit on an API: Combine INCR and EXPIRE in one Lua script to enforce 60 requests per minute per key.
- Make stock reduction atomic: Replace code that drives stock negative in a flash sale with a Lua script that checks and reduces every cart item in one step.
- Pull slow commands from SLOWLOG: Read SLOWLOG entries and find the five slowest commands and the keys they touched.
- Find big keys and split them: Find the biggest keys with --bigkeys and MEMORY USAGE and move the largest into a split structure.
- Tune persistence to a data loss target: Set RDB and AOF for a target of at most one second of data loss, kill the server and measure the loss.
- Lock down an exposed Redis: Restrict a server listening on all interfaces without a password to the local network with bind and protected-mode.
- Define an ACL user for the app: Create an ACL user that allows the app only its own key prefix and the commands it needs.
- Protect Redis with TLS and a hardening list: Make TLS mandatory, disable dangerous commands and write a script that checks the hardening list item by item.
About this course
You will build queue, ranking and approximate-counting patterns in Redis and learn to monitor and configure it securely.
What you will learn
- Data structure patterns
- Behaviour and patterns
- Operations
- Security
Prerequisites
You should be comfortable with the level 101 and 201 topics of the same path.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 301; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.