Lesson 4 / 18

String Commands

SET, GET, and atomic counters — the simplest Redis data type.

SET & GET

Every Redis key maps to a value. A string value can hold text, JSON, or numbers.

SET user:1:name "Ada"
GET user:1:name

Output:

OK
"Ada"

Atomic counters

INCR/DECR change a numeric string atomically — safe even with many clients hitting the same key at once.

SET page:views 0
INCR page:views
INCR page:views
INCRBY page:views 10

Output:

OK
(integer) 1
(integer) 2
(integer) 12

512MB limit

A single string value can hold up to 512MB — plenty for JSON blobs, but Redis isn't meant to store large files.