Redis Cheatsheet
Redis data types, commands, expiration, pub/sub, and performance patterns.
Redis is an in-memory data structure store used as a cache, message broker, and database. It supports rich data types: strings, hashes, lists, sets, sorted sets, and more — all accessed with atomic commands.
This cheatsheet covers the most useful commands for each data type, plus expiration, transactions, and pub/sub. Commands use the redis-cli syntax.
Strings
SET key valueGET keyINCR keyINCRBY key n / DECRBY key nSETEX key seconds valueMSET key1 val1 key2 val2Hashes
HSET key field valueHGET key fieldHGETALL keyHMSET key field1 val1 field2 val2HDEL key field [field ...]Lists
LPUSH key valueRPUSH key valueLPOP key / RPOP keyLRANGE key start stopLLEN keySets & Sorted Sets
SADD key memberSMEMBERS keySISMEMBER key memberSINTER key1 key2ZADD key score memberZRANGE key start stop [WITHSCORES]ZREVRANGE key start stop [WITHSCORES]Expiration & Keys
EXPIRE key secondsTTL keyDEL key [key ...]KEYS patternSCAN cursor [MATCH pattern]Pub/Sub & Transactions
PUBLISH channel messageSUBSCRIBE channel [channel ...]MULTI / EXECRedis Cheatsheet
Redis data types, commands, expiration, pub/sub, and performance patterns.
Redis is an in-memory data structure store used as a cache, message broker, and database. It supports rich data types: strings, hashes, lists, sets, sorted sets, and more — all accessed with atomic commands.
This cheatsheet covers the most useful commands for each data type, plus expiration, transactions, and pub/sub. Commands use the redis-cli syntax.
Strings
SET key value — Set a string value.GET key — Get a string value.INCR key — Atomically increment a number by 1. Creates key if not exists.INCRBY key n / DECRBY key n — Increment or decrement by a specific amount.SETEX key seconds value — Set a string value with a TTL (time-to-live) in seconds.MSET key1 val1 key2 val2 — Set multiple string keys atomically.Hashes
HSET key field value — Set a field in a hash.HGET key field — Get a single field from a hash.HGETALL key — Get all fields and values of a hash.HMSET key field1 val1 field2 val2 — Set multiple hash fields. Superseded by HSET with multiple pairs.HDEL key field [field ...] — Delete one or more hash fields.Lists
LPUSH key value — Prepend a value to a list (left side).RPUSH key value — Append a value to a list (right side).LPOP key / RPOP key — Remove and return the first/last element of a list.LRANGE key start stop — Get a range of elements from a list. 0 is first, -1 is last.LLEN key — Get the length of a list.Sets & Sorted Sets
SADD key member — Add a member to a set. Duplicates are ignored.SMEMBERS key — Return all members of a set.SISMEMBER key member — Check if a value is a member of a set. Returns 0 or 1.SINTER key1 key2 — Return the intersection of multiple sets.ZADD key score member — Add a member to a sorted set with a numeric score.ZRANGE key start stop [WITHSCORES] — Return members in a score range (low to high).ZREVRANGE key start stop [WITHSCORES] — Return members in reverse score order (high to low).Expiration & Keys
EXPIRE key seconds — Set a TTL on an existing key.TTL key — Get the remaining TTL in seconds. -1 means no expiry, -2 means key gone.DEL key [key ...] — Delete one or more keys.KEYS pattern — Find all keys matching a pattern. Use with caution in production (blocks Redis).SCAN cursor [MATCH pattern] — Cursor-based key iteration. Use instead of KEYS in production.Pub/Sub & Transactions
PUBLISH channel message — Send a message to a channel. Subscribers receive it in real-time.SUBSCRIBE channel [channel ...] — Subscribe to one or more channels and listen for messages.MULTI / EXEC — Start a transaction block. All commands between MULTI and EXEC run atomically.