Redis 8 cheatsheet
Redis 8: Keys and strings
11 common Redis 8 tasks.
Set a value that expires
Store a value that is deleted after 3600 seconds.
SET session:42 abc123 EX 3600
Set only if the key does not exist
Useful as a simple lock. Returns nil if the key exists.
SET lock:job1 1 NX EX 30
Check time to live
Seconds until expiry, -1 for no expiry, -2 if the key does not exist.
TTL session:42
Increment a counter
Atomically add 1 to a numeric value, creating it at 0 if missing.
INCR page:views
Find keys by pattern
Iterate over keys without blocking the server.
SCAN 0 MATCH user:* COUNT 100
Caution: Avoid KEYS * on a production server. It blocks Redis while it scans every key.