Redis CLI & In-Memory Data Store Cheat Sheet
The definitive Redis CLI reference: key TTL management, atomic counters (INCR), hash maps (HSET, HGETALL), list queues (LPUSH, BRPOP), sorted sets (ZADD), and memory diagnostics with 1-click copy.
Keys & Lifecycle (6 commands)
redis-cli -h 127.0.0.1 -p 6379 -a "mypassword"
Connects to a remote or local Redis instance using the command-line client.
PING
Tests connectivity to the Redis server. Returns PONG if healthy.
EXPIRE <key> 3600
Sets a Time-To-Live (TTL) timeout in seconds on the target key.
TTL <key>
Returns remaining lifetime in seconds (-1 = persistent, -2 = key expired/missing).
PERSIST <key>
Removes the existing expiration timeout, making the key permanently stored in memory.
DEL <key1> <key2>
Deletes one or more keys synchronously from memory.
Strings & Counters (4 commands)
SET <key> "value" EX 300 NX
Sets key with 300s TTL only if it does not already exist (distributed lock pattern).
GET <key>
Retrieves the string value stored at key.
INCR <counter_key>
Atomically increments the integer value of a key by one.
MGET <key1> <key2> <key3>
Batches multiple string lookups in a single round-trip network call.
Hashes (Objects) (3 commands)
HSET user:1001 name "Elena" role "admin" visits 42
Sets multiple field-value pairs in a hash object representing an entity.
HGETALL user:1001
Returns all fields and values stored in the specified hash object.
HINCRBY user:1001 visits 1
Atomically increments a specific numeric field inside a hash object.
Lists & Queues (3 commands)
LPUSH task_queue "job_payload_json"
Pushes an item onto the head (left side) of a list queue.
BRPOP task_queue 10
Blocking pop: removes and returns last item, or blocks up to 10s waiting for jobs.
LRANGE user_feed:101 0 19
Retrieves a slice of items from index 0 to 19 (pagination).
Sets & Sorted Sets (4 commands)
SADD tags:article:42 "tech" "cloud" "devops"
Adds unique member strings to an unordered mathematical set.
SISMEMBER tags:article:42 "cloud"
Checks if an element belongs to the set with O(1) time complexity.
ZADD leaderboard 1500 "user_alice" 2200 "user_bob"
Adds members with numeric scores into a sorted set for ranking algorithms.
ZREVRANGE leaderboard 0 9 WITHSCORES
Retrieves the top 10 highest-ranked members along with their scores.
Pub/Sub & Server Health (3 commands)
PUBLISH notifications "New invoice created"
Broadcasts a message to all subscribers listening on the notifications channel.
INFO memory
Inspects allocated memory, peak memory, RSS, and fragmentation ratio.
FLUSHDB ASYNC
Deletes all keys in the currently selected database non-blockingly.