Command Palette

Search for a command to run...

Hectal
Phase 1Beginner2 of 17 in Redis

Core Data Structures

Strings, hashes, lists, sets and sorted sets: the commands, the complexity, how each is stored, and the classic problem each one solves.

Every Redis design starts with choosing a data structure. The right choice makes an operation one atomic O(1) or O(log N) command; the wrong one turns it into a racy read-modify-write loop or an O(N) scan that blocks the server.

Each topic follows the same order: what problem the structure solves, the commands, how Redis stores it internally, the atomicity you get for free, the interview problem it's famous for, and how it fails at scale.

0/6 · 0%
6 topics ~89 min 13 code blocks & diagrams
Start with the first topic
1
1.1

Strings: Values, Counters, and Conditional Writes

A Redis string is a binary-safe byte array up to 512 MB. It holds cached blobs, integers you can increment atomically, and flags you can set conditionally with an expiry, which makes it the building block for counters, locks and rate limiters.

16 min 1 diagram 1 code practice

2
1.2

Hashes: Objects, Sessions, and Field-Level TTL

A hash maps field names to string values under one key: ideal for objects like users, sessions and carts. Small hashes are stored in a compact listpack, fields can be incremented atomically, and since Redis 7.4 individual fields can expire.

16 min 2 code practice

3
1.3

Lists: Queues, Recent Items, and Reliable Handoff

A list is an ordered sequence you push and pop at both ends in O(1), with blocking pops for worker queues. It's perfect for recent-items feeds and simple job queues, but a plain pop loses the job if the worker crashes, so reliable queues need LMOVE or Streams.

16 min 1 diagram 1 code practice

4
1.4

Sets: Membership, Tags, and Set Algebra

A set holds unique, unordered strings with O(1) add, remove and membership checks, plus server-side intersection, union and difference. It's the natural fit for tags, permissions, unique visitors (at small scale) and social graphs.

15 min 1 diagram 1 code practice

5
1.5

Sorted Sets: Rankings, Time Windows, and Priority

A sorted set keeps unique members ordered by a floating-point score, with O(log N) inserts, rank queries and range queries. It powers leaderboards, sliding-window rate limiters, delayed-job schedulers, priority queues and "latest N" timelines.

16 min 1 diagram 2 code practice

6
1.6

Choosing the Right Structure: A Decision Guide

Pick the structure from the question you must answer: "what's the value" (string), "what's this object's field" (hash), "what came next" (list or stream), "is it a member" (set), "what's the rank or range" (sorted set), "roughly how many unique" (HyperLogLog), "which bit" (bitmap), "what's nearby" (geo).

10 min 1 diagram 1 code practice