SQLancer
← All Cheat Codes Library / Cheat Codes / Redis
ðŸ”ī Redis Cheat Codes

Redis Cheat Codes

Redis Cheat Codes for string caching, hashes, lists, pub/sub, Lua scripts, and memory management. 20 essential cheat codes ready to copy and execute.

# 1 SET / GET Strings

Store and retrieve key-value string pairs.

Syntax:
SET key "value" / GET key
Working Example:
SET user:42 "Alex" / GET user:42
# 2 SET EX (TTL Expiration) Strings

Set key-value pair with TTL expiration seconds.

Syntax:
SET key "value" EX seconds
Working Example:
SET cache:session "token_123" EX 3600
# 3 HSET / HGETALL Hashes

Store and fetch structured hash fields.

Syntax:
HSET key field "val" / HGETALL key
Working Example:
HSET user:101 name "Alex" email "a@b.com" / HGETALL user:101
# 4 LPUSH / RPOP Lists

Push element to list head and pop from tail (queue).

Syntax:
LPUSH key "val" / RPOP key
Working Example:
LPUSH jobs "job_99" / RPOP jobs
# 5 SADD / SMEMBERS Sets

Add unique members to set and fetch all members.

Syntax:
SADD key "member" / SMEMBERS key
Working Example:
SADD tags:post:10 "sql" "nosql" / SMEMBERS tags:post:10
# 6 ZADD / ZREVRANGE Sorted Sets

Add member with score and fetch top leaderboard ranks.

Syntax:
ZADD key score "member" / ZREVRANGE key 0 -1 WITHSCORES
Working Example:
ZADD leaderboard 2500 "PlayerA" 1800 "PlayerB" / ZREVRANGE leaderboard 0 2 WITHSCORES
# 7 PUBLISH / SUBSCRIBE Pub/Sub

Publish message to channel and subscribe.

Syntax:
PUBLISH channel "msg" / SUBSCRIBE channel
Working Example:
PUBLISH news:updates "New release live!"
# 8 INCR / DECR Strings

Atomically increment or decrement integer key.

Syntax:
INCR key / DECR key
Working Example:
INCR page:views:42
# 9 EXPIRE / TTL Expiration

Set TTL expiration seconds on key and check remaining TTL.

Syntax:
EXPIRE key seconds / TTL key
Working Example:
EXPIRE rate:limit:ip 60 / TTL rate:limit:ip
# 10 DEL Keys

Delete specified key from Redis memory.

Syntax:
DEL key1 key2
Working Example:
DEL cache:user:42
# 11 EXISTS Keys

Check if key exists in memory.

Syntax:
EXISTS key
Working Example:
EXISTS session:active:10
# 12 SCAN Keys

Iterate over database keys safely without blocking.

Syntax:
SCAN cursor MATCH pattern COUNT n
Working Example:
SCAN 0 MATCH user:* COUNT 100
# 13 MULTI / EXEC Transactions

Execute atomic block of commands sequentially.

Syntax:
MULTI ... commands ... EXEC
Working Example:
MULTI; INCR visits; EXPIRE visits 60; EXEC;
# 14 MSET / MGET Strings

Set and get multiple key-value pairs simultaneously.

Syntax:
MSET k1 "v1" k2 "v2" / MGET k1 k2
Working Example:
MSET user:1 "A" user:2 "B" / MGET user:1 user:2
# 15 PFADD / PFCOUNT HyperLogLog

Track unique cardinality with 12KB memory footprint.

Syntax:
PFADD key "val" / PFCOUNT key
Working Example:
PFADD uv:2026-01-01 "ip_1" "ip_2" / PFCOUNT uv:2026-01-01
# 16 GEOADD / GEODIST Geospatial

Store spatial coordinates and measure distance.

Syntax:
GEOADD key long lat "member" / GEODIST key m1 m2 km
Working Example:
GEOADD cities -73.98 40.74 "NYC" -118.24 34.05 "LA" / GEODIST cities NYC LA km
# 17 EVAL (Lua Script) Scripting

Execute atomic server-side Lua script.

Syntax:
EVAL "script" numkeys key1 arg1
Working Example:
EVAL "return redis.call('get', KEYS[1])" 1 mykey
# 18 FLUSHALL Administration

Wipe all keys from all Redis databases.

Syntax:
FLUSHALL [ASYNC]
Working Example:
FLUSHALL ASYNC
# 19 INFO memory DBA

Inspect memory consumption and fragmentation.

Syntax:
INFO memory
Working Example:
INFO memory
# 20 CONFIG GET / SET Administration

Read or alter Redis runtime settings.

Syntax:
CONFIG GET param / CONFIG SET param val
Working Example:
CONFIG GET maxmemory / CONFIG SET maxmemory 2gb