1. Seed the counter
SET initializes the counter to the string "0"; INCR also treats a missing key as 0.
SET views 0Typorithm · easy
Step 1 of 8 · intro card
Strings & Keys
INCR and DECR atomically change an integer-string value by one, INCRBY by an arbitrary amount; because each operation is atomic they are safe for concurrent counters and rate limits, and a missing key is treated as 0.
Redis stores numbers as strings, but INCR views interprets that string as an integer and bumps it by 1, returning the new total. DECR does the same in reverse.
INCRBY views 10 adds an arbitrary amount in one step, and a matching DECRBY subtracts. All of these run as a single atomic operation on the server.
Atomicity is the key property: even with many clients hitting INCR at once, no increment is lost, which makes these commands ideal for page counters and rate limiters. If the key is missing, Redis treats it as 0 before applying the operation.
INCR/DECR change an integer by 1 atomically.
INCRBY adds an arbitrary amount N.
A missing key is treated as 0.
SET views 0
INCR views
INCRBY views 10
DECR views
GET viewsConnect each part of the code to the concept before you type.
SET initializes the counter to the string "0"; INCR also treats a missing key as 0.
SET views 0INCR atomically increments the integer value by 1 and returns the new total.
INCR viewsINCRBY adds an arbitrary amount — here 10 — in a single atomic step.
INCRBY views 10DECR atomically decrements the integer value by 1.
DECR viewsGET returns the counter's current value as a string.
GET viewsRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.