← All 65 books redis starters, one command per page Get the full edition · £10
One command per page

redis starters, one command per page

Eighteen steps for developers who installed Redis, cached one string and stopped: the key-value model, SET and GET with their options, INCR as an atomic counter, EXPIRE and TTL for keys that delete themselves, lists that push and range from either end, sets that ignore duplicates, hashes as rows, sorted sets that sort themselves, DEL and EXISTS, SCAN instead of KEYS, and pub/sub, one command per page.


Steve Hodgkiss 5 steps

A diagram, the classic trap, and one thing to go try this week. That's a page.

redis starters, one command per page

Eighteen steps for developers who installed Redis, cached one string and stopped: the key-value model, SET and GET with their options, INCR as an atomic counter, EXPIRE and TTL for keys that delete themselves, lists that push and range from either end, sets that ignore duplicates, hashes as rows, sorted sets that sort themselves, DEL and EXISTS, SCAN instead of KEYS, and pub/sub, one command per page.


Set in Space Grotesk, Inter and JetBrains Mono (SIL Open Font License).

Redis behaviour checked against the official command reference and develop guides at redis.io (docs/latest/commands and docs/latest/develop), all fetched and read during this build. Command syntax, defaults, return values and edge cases are named as those documents name them. Teaching conventions (one command a page) are named as conventions. This book quotes no verbatim passages and is an independent guide not affiliated with or endorsed by Redis Ltd.

General information only. Not professional advice; verify against your own Redis version and the current documentation.

Your purchase is for personal use only. You do not have redistribution rights: please do not share, resell, or republish this book or its pages.

© 2026 Steve Hodgkiss. All rights reserved. Personal use only; no redistribution rights.

Edition 1.0 · stevehodgkiss.net

Contents

Contents


Part 1 · The model
One verb, one key4
Part 2 · Strings
INCR5
Part 3 · Time
Keys that expire6
Part 4 · The keyspace
The scanner7
Part 5 · Messages
The whole keyspace8

Redis is an in-memory data structure store that can be used as a database, cache, streaming engine and message broker. Data lives in a keyspace: each key names one value, and commands operate on those keys. Per the redis.io develop quick starts.

redis starters · No. 01
The model

One verb, one key

Every key names one value

one key, one valuethe keyspaceuser:1queue:jobstags:7anaa lista set

Let's say Redis is a cache. It can be, and it's four other things.

The docs list the jobs: database, cache, streaming engine, message broker. Under all of them sits one model: a keyspace, a flat map where every key names one value. No tables, no joins. You point a command at a key and it does one thing well.

One key, one value, one verb at a time. That's the whole shape.

TRY THIS WEEK

Draw your app's data as ten keys with values on paper this week. If a value needs two names to be found, you've found your first design decision.

INCR key increments the integer value of a key by one, treating a missing key as 0 before the operation, and returns the value after the increment. It is limited to 64 bit signed integers and returns an error if the value cannot be represented as an integer. Per the redis.io INCR documentation.

redis starters · No. 02
Strings

INCR

The counter that can't race

in your appGET+ 1SETclient Aclient Braceon the serverINCR mycounter(integer) 11one command, no lost update

Let's say you count with GET, add one in code, and SET it back. Three round trips and a race.

INCR key does the whole thing on the server: add one, return the new value. Two clients INCR at once and both counts land, no lock, no lost update. A missing key starts at 0, so the first INCR answers 1. It's a string operation, Redis has no separate integer type, and it's limited to 64 bit signed values.

Counters, rate limits, view counts: one command, no race.

TRY THIS WEEK

Rate limit something this week: INCR a key per user per minute and treat the first reply, 1, as your signal. That's the counter half of a limiter built.

EXPIRE key seconds sets a timeout on a key; after the timeout expires, the key is automatically deleted. A key with a timeout is volatile. The timeout is cleared by commands that delete or overwrite the whole value, such as DEL, SET and GETSET, while INCR, LPUSH and HSET leave it untouched; PERSIST makes the key persistent again. Per the redis.io EXPIRE documentation.

redis starters · No. 03
Time

Keys that expire

EXPIRE arms a timer

sess:42anaat zerodeleted automaticallySET clears the timervolatile:a key witha timeoutINCR andHSET keep it

Let's say you delete old sessions with a nightly job. Redis folds the job into the key.

EXPIRE key seconds arms a timer; when it hits zero the key is deleted automatically. A key with a timeout is volatile. The trap is in the docs: commands that overwrite the whole value, like SET, clear the timer, while INCR, LPUSH and HSET leave it alone. Your session refreshes with SET, its timer is cleared, and the key lives forever.

The timer follows the value. Overwrite it, and the timer is gone.

TRY THIS WEEK

SET a key, EXPIRE it 60, then SET it again and run TTL. The -1 is the lesson: refresh with SET EX, or KEEPTTL.

SCAN iterates the set of keys in the database incrementally using a cursor. A full iteration starts with cursor 0 and calls SCAN until the returned cursor is 0 again. SCAN gives guarantees for full iterations: an element present in the collection from start to end of a full iteration is returned at some point. Per the redis.io SCAN documentation.

redis starters · No. 04
The keyspace

The scanner

Walk big databases in bites

the keyspaceSCAN 0cursor 17SCAN 17cursor 0, full iterationa key present from start to end of a full iteration is returned at some pointstart at 0, stop at 0

Let's say you must visit every key in production. Take bites, not the whole meal.

SCAN walks the keyspace by cursor: start at 0, it returns some keys plus the next cursor, and you loop until the cursor comes back 0, a full iteration. The guarantee in the docs: anything present from start to end of a full iteration is returned at some point. Each call is small, so the walk leaves room for everything else.

Start at 0, stop at 0. Small bites, no blockade.

TRY THIS WEEK

Write the six-line SCAN loop this week: cursor 0, take a bite, repeat until 0. It's the loop every cleanup script should already be.

The core Redis data types are strings, lists, sets, hashes and sorted sets, each with typed commands, plus generic key operations such as DEL, EXISTS, EXPIRE and SCAN, and pub/sub commands PUBLISH and SUBSCRIBE. Per the redis.io command reference groups.

redis starters · No. 05
Messages

The whole keyspace

Five shapes, one model

one keyspaceone key, one valuestringlistsethashzsetEXPIRESCANPUBLISH

Let's say Redis was a cache that also did pub/sub. It's one keyspace with five shapes of value.

Strings count and cache. Lists feed. Sets hold the unique. Hashes row the fields. Sorted sets rank. Around them, the same verbs apply everywhere: EXPIRE arms, DEL removes, SCAN walks, PUBLISH shouts. You now know the whole core: types, timers, traversal and messages.

One model, five shapes. Everything else is combinations.

TRY THIS WEEK

Close the book and list the five types with their verbs. Whatever you miss is the page to reread, not a gap in the model.

Index

Index


INCR5
Keys that expire6
One verb, one key4
The scanner7
The whole keyspace8