Programming74 entries
Redis Commands
Strings, hashes, lists, sets, sorted sets, pub/sub, streams, and transactions
1Connection & Server
redis-cli | Connect to local Redis instance |
redis-cli -h host -p 6379 | Connect to remote Redis |
redis-cli -a password | Connect with authentication |
AUTH password | Authenticate after connecting |
PING | Test connection (returns PONG) |
SELECT 1 | Switch to database 1 (0-15) |
INFO | Show server info and statistics |
INFO memory | Show memory usage details |
DBSIZE | Count keys in current database |
FLUSHDB | Delete all keys in current database |
FLUSHALL | Delete all keys in all databases |
2String Operations
SET key value | Set a string value |
GET key | Get a string value |
SET key value EX 3600 | Set with expiry (seconds) |
SET key value NX | Set only if key does not exist |
MSET key1 val1 key2 val2 | Set multiple keys at once |
MGET key1 key2 key3 | Get multiple values at once |
INCR counter | Increment integer value by 1 |
INCRBY counter 5 | Increment integer by N |
DECR counter | Decrement integer value by 1 |
APPEND key " more" | Append string to existing value |
STRLEN key | Get length of string value |
3Key Management
KEYS pattern* | Find keys matching pattern (slow) |
SCAN 0 MATCH pattern* COUNT 100 | Iterate keys safely (production-safe) |
EXISTS key | Check if key exists (returns 0/1) |
DEL key | Delete a key |
UNLINK key | Async delete (non-blocking) |
TYPE key | Get the type of a key |
RENAME key newkey | Rename a key |
EXPIRE key 300 | Set TTL in seconds |
PEXPIRE key 5000 | Set TTL in milliseconds |
TTL key | Get remaining TTL in seconds |
PERSIST key | Remove expiry from key |
4Hash Operations
HSET user:1 name "Alice" age 30 | Set hash fields |
HGET user:1 name | Get a single hash field |
HGETALL user:1 | Get all fields and values |
HMGET user:1 name age | Get multiple hash fields |
HDEL user:1 age | Delete a hash field |
HEXISTS user:1 email | Check if hash field exists |
HKEYS user:1 | List all hash field names |
HVALS user:1 | List all hash field values |
HINCRBY user:1 age 1 | Increment hash field value |
5List Operations
LPUSH queue item1 item2 | Push to head of list |
RPUSH queue item1 item2 | Push to tail of list |
LPOP queue | Pop from head of list |
RPOP queue | Pop from tail of list |
LRANGE queue 0 -1 | Get all items in list |
LRANGE queue 0 9 | Get first 10 items |
LLEN queue | Get list length |
LINDEX queue 0 | Get item at index |
BLPOP queue 30 | Blocking pop (wait up to 30s) |
6Set & Sorted Set
SADD tags "redis" "database" | Add members to a set |
SMEMBERS tags | Get all members of a set |
SISMEMBER tags "redis" | Check if member exists in set |
SCARD tags | Get set cardinality (count) |
SINTER set1 set2 | Intersection of two sets |
SUNION set1 set2 | Union of two sets |
ZADD leaderboard 100 "alice" | Add member with score to sorted set |
ZRANGE leaderboard 0 9 REV WITHSCORES | Get top 10 with scores |
ZRANK leaderboard "alice" | Get rank of member (0-based) |
ZSCORE leaderboard "alice" | Get score of member |
7Pub/Sub & Streams
SUBSCRIBE channel | Subscribe to a channel |
PUBLISH channel "message" | Publish message to channel |
PSUBSCRIBE pattern* | Subscribe to channels matching pattern |
XADD stream * field value | Add entry to stream |
XREAD COUNT 10 STREAMS stream 0 | Read from stream |
XLEN stream | Get stream length |
8Transactions & Scripting
MULTI | Start a transaction |
EXEC | Execute all queued commands |
DISCARD | Discard queued commands |
WATCH key | Watch key for optimistic locking |
EVAL "return redis.call('GET', KEYS[1])" 1 mykey | Execute Lua script |
BGSAVE | Trigger background save to disk |
BGREWRITEAOF | Trigger AOF rewrite |
Related Cheatsheets
JavaScript ES6+
Modern JavaScript syntax: destructuring, arrow functions, promises, modules, and built-in methods
Python Essentials
Python syntax, data structures, comprehensions, built-in functions, and common patterns
Regular Expressions
Regex syntax, character classes, quantifiers, groups, lookaheads, and common patterns