Checking your sign-in…
This lesson is in Phase 1 — ₹399, one-time
Pay once with UPI, card or netbanking. Keep it forever. Your progress saves, so you can stop and come back.
← Back to all lessonsRedis Lab — A Fast Memory Store
Phase 1 · The Data TierWhat this is and why it matters
Redis is a fast memory store. It keeps small answers in memory so they can be read in a blink.
Think of it like a small whiteboard next to a shop counter.
- The big record book sits in the back room. Finding an answer in it takes time.
- The whiteboard on the counter holds the few answers people ask for again and again.
- A worker glances at the whiteboard and answers at once.
- Nobody opens the big book for every small question.
In real systems, asking the main record store for every small answer is slow. A memory store takes that load off it.
This lab runs two Redis stores on your own computer: a main one and a copy that follows it. You will save fake values, set expiry times, use a counter, and see what happens when you try to write to the copy. Then the copy stops following and becomes a main store itself.
One idea per line, in order:
- Memory is the fast working space of a computer. Reading from memory is fast.
- A store keeps things by name, so you can ask for them back by that name.
- The main store is called redis-a in this lab.
- The copy is called redis-b in this lab. It follows redis-a.
- A copy takes reads only. It refuses writes.
- Expiry means a saved answer deletes itself after a set time.
- A counter is a number that goes up by one each time something happens.
All data in this lab is fake: made-up users, made-up login codes, made-up counts.
Test status
Syntax-checked only (20 November 2026). The compose file was checked for correct syntax. This lab was not run end-to-end on this machine, because this machine has no Docker. Follow it on your own machine with Docker, and if a step fails, read the error first — that is the real skill.
What this lab is
You will run two Redis stores on your own machine: a main one and a copy that follows it. You will save fake values, set expiry times, use a counter, and see what happens when you try to write to the copy. All data is fake.
What you need first
- Docker running. Lesson 0 shows how to install it and check it.
- The file in the folder
phase1/redis-lab/— verified on disk:docker-compose.yml. That is the only file the lab needs. It also holds a helper file calleddrill.sh, which the lab does not ask you to run. You do not need to open either file. The lab steps tell you the commands to run. - Do the Kafka lab and the PostgreSQL lab first if you are following the phase order.
Words you need, before you use them
- Redis — a store that keeps data in memory, so reads are very fast. It is used for caches, counters and short-term data.
- Key and value — Redis stores things by name. The name is the key. The thing stored is the value. Example: key
user:101, valueAsha. The colon:inuser:101is only a naming habit. It separates the kind of thing (user) from its number (101). Redis does not treat the colon specially. You could name the keyuser101instead. The colon only makes it easier for humans to read. - Cache — a fast copy of an answer, kept so you do not have to ask the slow record store again.
- Expiry (TTL) — a time limit on a key. TTL is short for "time to live", meaning how many seconds the key has left to live. When the time runs out, Redis deletes the key by itself.
- Replica — a copy that follows the main store. It takes reads only.
- Counter — a number stored in Redis that you add 1 to, again and again. Each add is one step.
- CRDT — short for Conflict-free Replicated Data Type. It is a way for two stores to accept writes at the same time and merge them. It is a paid feature in Redis products. This lab shows the idea in plain words in Step 7, and shows the free one-way copy instead. The free Redis in this lab does not have CRDT.
- One-way copy — one store follows another. Writes go to the main store only. The copy only reads.
- Two-way sync — two stores both accept writes, and merge the changes so both end up the same. That merge rule is the CRDT idea.
(nil)— the word redis-cli prints when a key has nothing stored under it. It means "nothing here". It is not an error. It is the answer "this key does not exist right now".redis-cli— the command-line tool for talking to Redis. It runs inside the container. The letterscliare short for "command-line interface", meaning a tool you use by typing.- PONG — the answer Redis gives when you ask it "are you alive?" with the
pingcommand.pingis the question,PONGis the answer. If you seePONG, the store is up and answering. - Volume — a named place on your machine where Docker keeps a container's data. The data lives in a volume, so it survives a restart. Wiping the volume wipes the data.
- Append-only file — a file Redis writes every change into, so data survives a restart. The lab turns this on with
--appendonly yesin the filephase1/redis-lab/docker-compose.yml. You do not type that flag yourself. It is already in the compose file. In real work, check the disk settings before you trust it. - Practice data — all values in this lab are fake, on your own machine, for learning only.
The doors (ports) in this lab
redis-a, the main store, answers on door6379on your machine.redis-b, the copy, answers on door6380on your machine. Inside its own container, the copy still uses door6379, but from outside you reach it on6380. That is why two stores can run on one machine without fighting over the same door.- You do not type these door numbers in the commands below, because the commands run inside the containers. The door numbers matter only if another program on your machine already uses door
6379. If a start fails withport is already allocated, it means the door is already held. Stop the other program that uses it, or stop the old containers, then try again.
Step 1 — Start both stores
First, move your terminal into the lab folder. The folder is phase1/redis-lab/. Type this, then press Enter:
cd phase1/redis-labWord by word: cd — short for "change directory". It moves your terminal into a folder. phase1/redis-lab — the folder to move into. This works from the folder that holds phase1 (for example, your Downloads folder, or wherever you unzipped the kit). If your terminal is already inside the phase1 folder, use the shorter form instead: cd redis-lab.
To check you are in the right place, run ls. You should see docker-compose.yml and drill.sh in that list.
What this is: start both Redis stores together. Why we run it: nothing else in this lab can work until both stores are running.
Type this, then press Enter:
docker compose up -dWord by word:
docker— the Docker tool.compose— the part of Docker that starts several containers together from one file.up— start everything listed in the file.-d— short for detached. It means run in the background and give me my terminal back, instead of filling my screen with logs.
What you should see, line by line:
[+] Running 2/2
✔ Container redis-a Started
✔ Container redis-b Started[+] Running 2/2— 2 out of 2 containers are running.Container redis-a Started— the main store container started.Container redis-b Started— the copy container started.- How to tell it worked: both lines say
Started.
Now check they are both up. What this is: ps lists the containers Compose is running. Why we run it: the start lines scroll past fast, and this check proves both containers are still up right now.
Type this, then press Enter:
docker compose psWord by word:
docker compose— the Docker Compose tool, as above.ps— short for "process status". It lists the running containers.
What you should see: a table with redis-a and redis-b, each with STATUS Up. The real table has more columns than the example below. What matters is both names, each with STATUS Up.
NAME STATUS
redis-a Up
redis-b UpNow check they answer. What this is: ping asks a Redis store "are you alive?" Why we run it: a container can say Up and still not be ready to answer. PONG proves it is answering.
Type this, then press Enter:
docker exec redis-a redis-cli pingWord by word:
docker exec— run a command inside a container that is already running.execmeans execute, or run.redis-a— the container name. This is the main store container. Check the name:redis-a, notredis-b.redis-cli— the tool for talking to Redis. It runs inside the container.ping— the Redis command that asks "are you alive?"
What you should see:
PONGPONGis the answer toping. It means the store is up and answering.
If it breaks: if ping shows nothing, wait 10 seconds and try again. Redis starts fast, but the first start downloads the image. An image is the recipe Docker uses to build a container. The first download takes time. You can tell the download is done when the ping command answers PONG.
Step 2 — Save and read a value
What this is: save one fake user in the main store, then read it back. Why we run it: it proves the main store saves and returns values.
Save a fake user. Type this, then press Enter:
docker exec redis-a redis-cli SET user:101 AshaWord by word:
docker exec redis-a redis-cli— run the Redis tool inside the main store container, as in Step 1.SET— the Redis command that saves a value.SETmeans "store this".user:101— the key, or the name to store it under.useris the kind of thing.101is its number. The colon is only a naming habit, as explained above.Asha— the value, or the thing stored. This is a fake name, made up for this lab.
What you should see:
OKOKmeans the save worked. That is the whole answer. There is no more detail to read.
If it breaks: Could not connect means redis-a is not up yet. Run docker compose ps and wait until it shows Up.
Read it back. Type this, then press Enter:
docker exec redis-a redis-cli GET user:101Word by word:
docker exec redis-a redis-cli— run the Redis tool inside the main store container.GET— the Redis command that reads a value back.GETmeans "give me the value stored under this name".user:101— the key to read. It must match the key you saved exactly, including the colon and the number.
What you should see:
"Asha""Asha"is the value you saved. The quotes are part of how redis-cli shows a value. The value stored isAsha, without quotes. The quotes are only display marks.- How to tell it worked: the answer is the name you saved.
If it breaks: if you see (nil) ("nothing here"), the SET step never saved. (nil) means no value is stored under that key. Run the SET command again and check it prints OK.
Step 3 — Set a value that deletes itself
What this is: save a login code that lasts 60 seconds, then watch it disappear. Why we run it: this is how login codes and short-lived sessions work. The store cleans up by itself. Nobody has to delete the code by hand.
Save a login code that lasts 60 seconds. Type this, then press Enter:
docker exec redis-a redis-cli SETEX login-code:101 60 482913Word by word:
docker exec redis-a redis-cli— run the Redis tool inside the main store container.SETEX— the Redis command that saves a value with an expiry time.SETEXmeans "set with expiry". It isSETplus a time limit.login-code:101— the key.login-codeis the kind of thing.101is its number.60— the time limit, in seconds. The key will live for 60 seconds from this command. This number comes before the value. The order matters: key, then seconds, then value.482913— the value, the fake login code. This is a made-up six-digit code, not a real code. It is fake, for practice only.
What you should see:
OKOKmeans the save worked.
Check how long is left. What this is: TTL asks how many seconds a key has left to live. Why we run it: it proves the countdown is running.
Type this, then press Enter:
docker exec redis-a redis-cli TTL login-code:101Word by word:
TTL— short for "time to live". It asks "how many seconds does this key have left?"login-code:101— the key to check.
What you should see: a number near 60. It counts down: 58, 57, and so on. Your number depends on how many seconds passed between the SETEX command and this check.
5858means 58 seconds are left. The key was saved 60 seconds ago in the example, and 2 seconds passed before the check. Your number will be different. That is fine.- How to tell it worked: the answer is a number near 60, counting down.
Two other TTL answers you may see, and what they mean:
-2means the key is already gone. Its 60 seconds ran out before you checked. Run the SETEX command again.-1means the key exists but has no expiry time. That should not happen for this key, because SETEX always sets an expiry. If you see-1, you are checking a different key, or the key was saved with plainSETinstead ofSETEX.
Wait 65 seconds and read it again. Type this, then press Enter, after waiting a full 65 seconds:
docker exec redis-a redis-cli GET login-code:101What you should see:
(nil)(nil)means "nothing here". The key deleted itself when its time ran out.- How to tell it worked: the code is gone. That is the expected result, not a failure.
If it breaks: if the code is still there after 65 seconds, check you waited long enough. The key lives for a full 60 seconds from the SETEX command, not from when you first read it. Count 65 seconds from the moment you pressed Enter on the SETEX command, then read it again.
Step 4 — Use a counter
What this is: a number that goes up by one each time something happens. Why we run it: counters are the simplest thing Redis does well. In the end-to-end lab, a worker does this every time an order is saved. That is how the app shows "how many orders" without asking the record store.
Type these five commands, one at a time, pressing Enter after each:
docker exec redis-a redis-cli SET orders:count 0
docker exec redis-a redis-cli INCR orders:count
docker exec redis-a redis-cli INCR orders:count
docker exec redis-a redis-cli INCR orders:count
docker exec redis-a redis-cli GET orders:countWord by word:
SET orders:count 0— save a key calledorders:countwith the value0. This sets the counter to zero before you start counting.INCR— short for increment, which means add 1. It adds 1 to the stored number and prints the new number.INCR orders:count— add 1 to the counter. There are three INCR commands, so the counter goes 0, then 1, then 2, then 3.GET orders:count— read the counter back.
Each of the five commands prints its own answer:
- After
SET orders:count 0, you should seeOK. - After the first
INCR orders:count, you should see1. - After the second
INCR, you should see2. - After the third
INCR, you should see3. - After
GET orders:count, you should see"3".
What you should see at the end:
"3""3"is the final counter value. Each INCR added 1. Three INCRs after starting at 0 gives 3.- The quotes are part of how redis-cli shows a value. The value stored is
3. - How to tell it worked: the final answer is
"3", and the three INCR answers before it were1,2, and3, in order.
If it breaks: if GET shows "0", the first SET step was skipped, and the counter never started. Run SET orders:count 0 first, then the three INCRs. If GET shows a number higher than "3", you ran the INCR commands more than three times. That is fine for learning, but start again from SET orders:count 0 if you want a clean "3".
Step 5 — Read the same values from the copy
What this is: read the values you saved on the main store, but ask the copy instead. Why we run it: it proves the copy follows the main store. The copy should already have the same values.
Type these two commands, one at a time, pressing Enter after each:
docker exec redis-b redis-cli GET user:101
docker exec redis-b redis-cli GET orders:countWord by word:
docker exec redis-b— run a command inside the copy container. Check the name:redis-b, notredis-a.redis-cli GET user:101— read the value stored under the keyuser:101.redis-cli GET orders:count— read the value stored under the keyorders:count.
What you should see, one answer per command:
"Asha"
"3""Asha"is the answer to the first command."3"is the answer to the second command.- How to tell it worked: the copy shows the same two values you saved on the main store.
If it breaks: if either shows (nil), the copy has not caught up yet. Wait 10 seconds and read again.
Now check what the copy thinks it is. What this is: INFO replication asks a Redis store to describe its replication state: what role it has, and which store it follows. Why we run it: the two values above prove the data copied. This command proves the copy knows it is a follower.
Type this, then press Enter:
docker exec redis-b redis-cli INFO replicationWord by word:
docker exec redis-b redis-cli— run the Redis tool inside the copy container.INFO— the Redis command that prints information about the store.replication— the topic to print. It means "tell me about copying and following".
What you should see, line by line:
# Replication
role:slave
master_host:redis-a
master_port:6379# Replication— a heading. The#mark means this line is a section heading, not data.role:slave— the role line. It says this store is a replica: a copy that follows the main store. Note:slaveis the old word for replica — old output may still show it, and it means replica.master_host:redis-a— the main store it follows is namedredis-a. The output uses the old wordmasterfor the main store — the lab calls it the primary.hostmeans the machine or container name.master_port:6379— the primary store's door number is6379. That is redis-a's door, as listed at the top of this lesson.- The real output is longer than the four lines above. It has more lines about the copy state. The lines that matter are the
roleline and themaster_hostline. - How to tell it worked: the role line shows the copy is a replica (it prints
role:slave) and the host line saysredis-a. That is the proof it is following the main store.
If it breaks: if the role shows the main store's role (it prints role:master), the copy never linked to the main store. That role means "I am a main store, I follow nobody". Restart the copy with the command below, then wait 10 seconds. What this is: restart stops a service and starts it again. Why we run it: a fresh start makes the copy link to the main store again.
docker compose restart redis-bWord by word: docker compose restart redis-b — restart the service named redis-b.
Step 6 — Try to write on the copy (it must refuse)
What this is: a save command aimed at the copy. Why we run it: a one-way copy takes reads only. Trying a write and watching it fail is the proof. The error is the expected result. Do not try to fix it.
Type this, then press Enter:
docker exec redis-b redis-cli SET user:102 RaviWord by word:
docker exec redis-b redis-cli— run the Redis tool inside the copy container. Check the name:redis-b, notredis-a.SET user:102 Ravi— save a key calleduser:102with the valueRavi, a fake name.
What you should see:
(error) READONLY You can't write against a read only replica.(error)— the command failed.READONLY— the reason: this store is read-only.You can't write against a read only replica.— the plain-English reason: you cannot save a value on a copy that only follows.- How to tell it worked: you see this error. The error IS the proof. A one-way copy takes reads only. This is correct and expected.
If it breaks: if the SET returns OK instead of the READONLY error, you ran it on redis-a by mistake. Check the container name in the command (redis-b, not redis-a) and try again.
Step 7 — The two-way idea, in plain words
What this is: an idea, not a command. There is nothing to type in this step. Why it is here: so you understand what the free lab does NOT do.
What if two stores both accept writes at the same time? Then they must merge the changes. That merge rule is called a CRDT. It is a paid feature in Redis products. The free Redis in this lab does not have it.
The idea is the same as a shared document. If two people change the same line at the same time, the system needs a rule for which change wins. With a CRDT, the rule is built into the data itself, so both copies end up the same without arguing.
For this lab, remember this: one-way copy is free and simple. Two-way copy is a paid feature with rules you must understand before you use it. The lesson does not name which paid Redis product sells it. Do not go and buy anything for this step. The idea is the lesson. The free one-way copy in Steps 1 to 6 is the skill.
Clean up
What this is: stop both stores and remove their containers. Why we run it: the lab is done, and the next lab should start clean.
Type this, while you are inside the phase1/redis-lab/ folder, then press Enter:
docker compose downWord by word:
docker compose down— stop the containers and remove them.downis stronger thanstop:stopleaves the containers in place so you can start them again;downremoves them.
What you should see:
✔ Container redis-a Removed
✔ Container redis-b Removed- The tick
✔means done. Each line says one container was removed.
If it breaks: No such container means the stores are already stopped. Nothing to do.
down versus down -v — read this before you wipe anything
The data is in named volumes, so it survives a restart. A volume is a named place on your machine where Docker keeps a container's data. docker compose down removes the containers but leaves the volumes, so the data is still there the next time you start. Run the command below to wipe it. What this is: down -v stops the containers, removes them, and wipes the volumes too. Why we run it: only when you want the data gone for good.
docker compose down -vWord by word: docker compose down stops and removes the containers. -v means also wipe the volumes. Without -v, the data survives. With -v, the data is gone.
The data was fake, so losing it is fine. But do not run down -v by accident when you meant to keep your counter and values for the next step. If you run the drill below, do it before this wipe.
What you can now say, truthfully
"I ran two Redis stores, saved and read values, set keys that expire by themselves, used a counter, and proved a replica takes reads only."
What this lab does NOT cover
- Redis Cluster (many nodes sharing the data) is a bigger setup. The ideas are the same; the setup is bigger. A cluster splits the data across many nodes instead of copying all of it to one follower.
- Redis persistence (saving to disk) is on in this lab with
--appendonly yes, so data survives a restart. That flag lives in the filephase1/redis-lab/docker-compose.yml, on the line that starts each store. You do not type it. In real work, check the disk settings before you trust it. - The Advanced section at the end of this lesson now covers memory limits, eviction, Sentinel, Cluster, persistence tuning, and auth.
Failure drill — Promote the copy
This drill proves a copy can become a main store, and take writes, when you tell it to stop following. Do Steps 1 to 5 first, so the copy already holds the same data as the main store. Step 6 is not needed before the drill, because Step 6 only proves the copy refuses writes. The drill is the opposite: it makes the copy accept writes. One warning: if you already ran Clean up above, the stores are stopped and the drill cannot run. Start them again first, from inside the folder phase1/redis-lab/, with docker compose up -d — the data is still in the volumes, so nothing is lost — then do the drill. (Unless you ran down -v, which wipes the volumes: then the data is gone, and you must redo Steps 1 to 5 first.)
Drill Step 1 — Tell the copy to stop following
Run this from inside the folder phase1/redis-lab/. Type this, then press Enter:
docker exec redis-b redis-cli REPLICAOF NO ONEWord by word:
docker exec redis-b redis-cli— run the Redis tool inside the copy container.REPLICAOF— the Redis command that sets which store this store follows.REPLICAOFmeans "be a replica of".NO ONE— follow nobody. The two words together mean "stop following". After this command, the copy follows no main store. It stands alone.
What you should see:
OKOKmeans the command worked. The copy stopped following.
If it breaks: if it shows an error, redis-b is not up. Run docker compose ps and wait until it shows Up.
Drill Step 2 — Check what the copy thinks it is now
Type this, then press Enter:
docker exec redis-b redis-cli INFO replicationThis is the same command as Step 5. What you should see now is one line:
role:masterrole:master— the copy is now a main store.masteris the old word for a main store. It no longer follows redis-a.- The real output is longer than this one line. Find the
role:line in it. That is the line that matters. - How to tell it worked: the role line changed from
slavetomaster.
If it breaks: if the role still shows slave, wait 10 seconds and check again. The change takes a moment.
Drill Step 3 — Prove it takes writes now
Type this, then press Enter:
docker exec redis-b redis-cli SET user:102 RaviThis is the same save command that failed in Step 6. Word by word: save a key called user:102 with the value Ravi, inside the copy container.
What you should see:
OKOKmeans the save worked. The copy now accepts writes.
Read it back. Type this, then press Enter:
docker exec redis-b redis-cli GET user:102What you should see:
"Ravi""Ravi"is the value you just saved. The copy saved a value of its own.
If it breaks: if the SET still shows the READONLY error, Drill Step 1 did not take. Run REPLICAOF NO ONE again and check it prints OK.
Checklist — tick each one when you have seen it:
- ☐ The copy stopped following:
REPLICAOF NO ONEprintedOK. - ☐ The copy is now a main store:
INFO replicationshowsrole:master. - ☐ The copy takes writes: the new value saved and read back.
Save your proof
The proof for this lab is the promoted copy: role:master in its replication info, and the counter value it holds. Save both with these commands, run from inside the folder phase1/redis-lab/, after the drill.
First, make the proof folder if it does not exist. Type this and press Enter:
mkdir -p ../portfolio/proofWord by word:
mkdir— short for "make directory". It makes a new folder.-p— make the parent folders too, if they are missing, and do not complain if the folder already exists.../portfolio/proof— the path to the folder. The two dots..mean "go up one folder". You are inphase1/redis-lab/...takes you up tophase1/. Thenportfolio/prooftakes you down into theportfoliofolder, then into theprooffolder inside it. So the full folder isphase1/portfolio/proof/.
Then save the replication info. Type this and press Enter:
docker exec redis-b redis-cli INFO replication > ../portfolio/proof/redis-promoted.txtWord by word:
docker exec redis-b redis-cli INFO replication— ask the copy for its replication info, as in Drill Step 2.>— redirect. It means "send the output into a file, instead of printing it on the screen". It overwrites the file if the file already exists.../portfolio/proof/redis-promoted.txt— the file to write. It lives inphase1/portfolio/proof/, and its name isredis-promoted.txt.
Then add the counter value to the same file. Type this and press Enter:
docker exec redis-b redis-cli GET orders:count >> ../portfolio/proof/redis-promoted.txtWord by word:
docker exec redis-b redis-cli GET orders:count— read the counter from the copy.>>— redirect and append. It means "add the output to the end of the file, without erasing what is already there". One>overwrites. Two>>appends. That is the difference, and it matters here: the first command used one>, which created the file. This command uses two>>, which adds the counter to the end of the same file.../portfolio/proof/redis-promoted.txt— the same file as above.
Open the file and check it shows role:master and "3". That file is your proof. The "3" is the counter value from Step 4. If your counter shows a different number because you ran INCR extra times, that number is your proof. It must match what your own counter actually held.
What you should see: nothing in the terminal when you run the save commands. The output went into the file, not the screen. Silence means it worked.
If it breaks: if the file is empty, the drill did not run yet. Do the drill first (Drill Steps 1 to 3 above), then save again.
Reset after the drill
Run this from the phase1 folder to wipe the drill and start fresh. What this is: reset.sh is a helper script in the phase1 folder. Its argument tells it which lab folder to wipe. Why we run it: it stops both stores and wipes the data, then prints that it is done.
Move your terminal into the phase1 folder first. Then type this and press Enter:
bash reset.sh redis-labWord by word:
bash— the program that runs script files.reset.sh— the script file. It lives in thephase1folder. That is why you must be insidephase1first.redis-lab— the argument. It tells the script which lab folder to wipe. It is the folder nameredis-lab, insidephase1.
What you should see: the script stops both stores and wipes the data, then prints that it is done.
If it breaks: Permission denied means the script is not marked runnable. Runnable means the file is allowed to run as a program. Fix it with the command below, then try again. What this is: chmod +x adds the run permission to a file. Why we run it: without the run permission, your machine refuses to run the script.
chmod +x reset.shWord by word: chmod changes file permissions. +x means add the execute (run) permission. reset.sh is the file.
Or, from inside the folder phase1/redis-lab/, the plain way: run the command below. What this is: down -v stops the containers, removes them, and wipes the volumes. That stops both stores and wipes the data. The data was fake.
docker compose down -vOne honest note: after this drill you have two main stores, redis-a and redis-b, and they do not talk to each other. A value saved on one does not appear on the other. That is why the reset matters. Start fresh before the next lab.
Advanced — Memory limits, eviction, Sentinel, Cluster, persistence, and auth
This section is for the reader who already did the lab above. It covers the topic the review of this kit flagged as missing: memory limits and eviction — plus Sentinel and Cluster at concept level, persistence tuning, and auth. The commands were checked against this lab's own files and the Redis docs. The eviction drill changes the lab's settings, so run it on a fresh lab and reset after, as the drill says.
Advanced 1 — Memory limits: the default is no limit
What this is: maxmemory is the most memory Redis is allowed to use for its data. Why it matters: by default it is 0, which means no limit. Redis keeps adding keys until the machine runs out of memory, and then the operating system kills it. That is the most common Redis outage in real work, and it is entirely preventable.
Check the current setting on the lab's main store:
docker exec redis-a redis-cli CONFIG GET maxmemoryWord by word: CONFIG GET asks for a setting's current value. What you should see: maxmemory followed by 0. Zero means no limit. Check how much memory is actually used:
docker exec redis-a redis-cli INFO memoryRead the line used_memory_human — the memory Redis is using now, in human units like 1.20M. Then set a limit. Pick a number smaller than the machine's memory, with room left over for the operating system and for Redis's own background work:
docker exec redis-a redis-cli CONFIG SET maxmemory 100mbWord by word: CONFIG SET changes a setting while Redis is running, with no restart. 100mb is the limit: 100 megabytes. What you should see: OK. Now check it stuck:
docker exec redis-a redis-cli CONFIG GET maxmemoryWhat you should see: 104857600 — the same 100 megabytes, now written as bytes. One warning: CONFIG SET does not survive a restart. The setting is lost when the container restarts. To make it permanent, put it in the command line in docker-compose.yml, the same way the lab already puts --appendonly yes there:
command: redis-server --appendonly yes --maxmemory 100mb --maxmemory-policy allkeys-lru(The policy in that line is explained next. Add both settings together — a limit without a policy is only half the fix.)
Advanced 2 — Eviction: what happens when the memory is full
What this is: an eviction policy is the rule Redis follows when the memory is full and a new write arrives: which old keys to delete to make room. Why it matters: without a policy, the default is noeviction — Redis deletes nothing and answers every new write with an error: OOM command not allowed when used memory > 'maxmemory'. Your app gets errors instead of a working cache. With the right policy, Redis quietly deletes old keys and keeps working.
The policies, in plain words. allkeys means "any key may be deleted". volatile means "only keys that have an expiry time may be deleted" — a key with no expiry is never touched, so if none of your keys expire, a volatile policy behaves exactly like noeviction and writes still fail.
noeviction— the default. Delete nothing. New writes fail with the OOM error. Right when Redis holds data you cannot lose (a queue, a session), wrong for a cache.allkeys-lru— delete the key that has not been used for the longest time. The safe default for a pure cache.volatile-lru— the same, but only among keys that have an expiry time.allkeys-lfu— delete the key used least often. Better than LRU when a few keys get most of the traffic.volatile-lfu— the same, but only among keys with an expiry.allkeys-random— delete a random key.volatile-random— the same, but only among keys with an expiry.volatile-ttl— delete the key whose expiry time is nearest.
Set the policy before you set the limit — that order matters. If you set a limit below the memory already used while the policy is still noeviction, writes start failing at once. With the policy set first, Redis evicts instead:
docker exec redis-a redis-cli CONFIG SET maxmemory-policy allkeys-lruWhat you should see: OK. Now the drill: prove eviction happens. Set a tiny limit, fill the store past it, and watch old keys vanish. Do this on a fresh lab run — it deletes keys.
docker exec redis-a redis-cli CONFIG SET maxmemory 1mb
docker exec redis-a redis-cli CONFIG SET maxmemory-policy allkeys-lruThen fill it. This loop writes 300 keys of about 10 kilobytes each — about 3 megabytes into a 1-megabyte limit:
for i in $(seq 1 300); do docker exec redis-a redis-cli SET "fill:$i" "$(head -c 10000 /dev/zero | tr '\0' 'x')" > /dev/null; doneWord by word: for i in $(seq 1 300) counts from 1 to 300. head -c 10000 /dev/zero | tr '\0' 'x' makes a 10,000-letter string of x. Each SET stores one key. It takes a while — 300 separate commands. Now check what happened:
docker exec redis-a redis-cli INFO stats | grep evicted_keys
docker exec redis-a redis-cli DBSIZE
docker exec redis-a redis-cli GET fill:1What you should see: evicted_keys is a number bigger than zero — that is the count of keys Redis deleted to make room. DBSIZE is far below 300. GET fill:1 answers (nil) — the oldest key is gone. The exact numbers depend on your machine; what matters is that evicted_keys moved and old keys are gone. If nothing evicted, your values were too small — make them bigger and try again. Then reset the lab so the next lesson starts clean:
docker compose down -vThat wipes the data, as the lab already teaches. Also know: INFO stats | grep evicted_keys is the check to run in real work whenever someone says "keys are disappearing" — if that number is climbing, eviction is the cause, not a bug. And the replica ignores its own memory limit by default (it follows the primary instead), so set the same limits on every node, primary and replica alike.
Advanced 3 — Sentinel and Cluster, at concept level
What this is: Sentinel is a watcher that promotes a replica when the primary dies — the Redis version of Patroni. Cluster is a bigger setup where the data is split across many nodes, so no one node holds everything. Why they matter: the lab's manual promotion (the failure drill) is done by a human typing commands. In real work, a human is too slow at 3am.
- Sentinel: three or more small watcher programs watch the primary. When enough watchers agree the primary is dead, one of them promotes a replica and tells the apps the new address. Three watchers, not two — two cannot vote a majority, the same quorum rule as Patroni's three nodes. What to check: the watchers must agree, and the apps must ask Sentinel for the current primary instead of remembering one address forever.
- Cluster: the data is split by key across many nodes. Each key lives on one node, and each node has its own replica. It scales past one machine's memory, but a key can only be found by asking the right node, and commands that touch many keys at once (like the lab's simple operations) behave differently. What to check: whether any node is down, and whether keys are spread evenly — one overloaded node means the split is uneven.
- CRDT / active-active: the lab's notes call this "a paid feature in Redis products" without naming the product. The product is Redis Enterprise: it lets two clusters in different regions both take writes to the same data and merge them. It is a paid product, and it is the only way to get true active-active in Redis. Do not promise it from this lab.
This section gives no Sentinel or Cluster commands: both are multi-machine setups this one-machine lab does not run. Know the ideas, the quorum rule, and what to check.
Advanced 4 — Persistence tuning: AOF and snapshots
What this is: the lab turns on AOF (append-only file) with --appendonly yes — every write is also written to a log file, so data survives a restart. Redis has a second way: RDB snapshots — a full copy of the data saved to disk every so often. Why it matters: AOF and RDB fail differently. AOF can lose about a second of writes (see below). RDB can lose everything since the last snapshot. Real setups often run both.
appendfsync— how often Redis flushes the AOF log to disk.everysec(the default) flushes once a second: fast, and you can lose at most one second of writes.alwaysflushes on every write: safest, slowest.nolets the operating system decide: fastest, least safe. Check it withCONFIG GET appendfsync.save— the snapshot rule:save 3600 1means "if at least 1 key changed in 3600 seconds, save a snapshot". The usual defaults aresave 3600 1,save 300 100,save 60 10000. Check it withCONFIG GET save.BGSAVE— save a snapshot now, in the background.BGREWRITEAOF— rewrite the AOF log now, dropping writes that are already overwritten, so the file shrinks. Both are commands you type inredis-cli.INFO persistence— the status page for all of this: whether AOF is on, how big the log file is, whether a rewrite or a snapshot is running right now.
The sizing rule from the memory section applies here too: leave free memory for the background save, because Redis copies its memory while it saves. A memory limit set at 100% of the machine will kill the save.
Advanced 5 — Auth and TLS basics
What this is: auth means a password before Redis answers. TLS means scrambled traffic. Why it matters: this lab's Redis has NO password — the error decoder says so plainly — and it listens only on your own machine. That is safe for learning and unsafe anywhere else. An open Redis with no password is one of the most commonly attacked things on the internet.
- Set a password while running:
CONFIG SET requirepass <a password you choose>, then every later command needsAUTH <that password>first. Make it permanent by puttingrequirepassin the config file or on the command line, the same way asmaxmemoryabove. Never put the password in a file that goes to a shared repository. - ACLs (access control lists, Redis 6 and later): instead of one password for everyone, make one user per app, each allowed only its own commands and keys —
ACL SETUSER. One app's password then cannot delete another app's keys. - TLS: Redis can listen on a TLS port with certificate files, so traffic is scrambled. Setting it up needs certificate files this lab does not create, so no commands here — know the name and the rule: never expose port 6379 beyond your own machine. The lab binds it to
127.0.0.1only, and that is the one protection it has.
What you can now say, truthfully — advanced
- "I set a Redis memory limit and an eviction policy, and watched eviction happen —
evicted_keysclimbing and old keys gone." (Only if you did Advanced 2.) - "I know the default Redis policy is
noevictionwith no memory limit, and why that combination fails with OOM errors instead of evicting." (Only if you did Advanced 1 and 2.) - "I can explain Sentinel, Cluster, AOF vs RDB, and
appendfsyncin plain words, and what to check on each." (Only if you did Advanced 3 and 4.) - "I know this lab's Redis has no password, and what
requirepass, ACLs, and TLS add in real work." (Only if you did Advanced 5.)
Quick check — try it yourself
Question: In the terminal, type: docker exec redis-a redis-cli ping — what one-word reply shows the memory store is awake?
Open the practice terminal to test this →
Show answer
You should see PONG.