Skip to content

Latest commit

 

History

History
241 lines (191 loc) · 12.4 KB

File metadata and controls

241 lines (191 loc) · 12.4 KB

Appendix A — Command Quick Reference

A categorized cheat sheet of the most practical Redis 7.x commands. This is not an exhaustive list—see the official command reference for every option and flag.

Commands marked (7.0+) require Redis 7.0 or later. Prefer UNLINK over DEL for large keys in production when you can tolerate asynchronous memory reclamation.


Keys & General

Command Description
DEL key [key ...] Delete one or more keys synchronously; blocks until memory is reclaimed.
UNLINK key [key ...] Delete keys asynchronously; preferred for large values in production.
EXISTS key [key ...] Return count of keys that exist (0–N).
TYPE key Return the data type of a key (string, list, set, etc.).
RENAME key newkey Atomically rename a key; overwrites newkey if it exists.
EXPIRE key seconds [NX|XX|GT|LT] Set a timeout in seconds; optional NX/XX/GT/LT conditions.
EXPIREAT key unix-time-seconds Set expiration as a Unix timestamp (seconds).
PERSIST key Remove the expiration from a key.
TTL key Return remaining time to live in seconds (-1 = no expiry, -2 = missing).
SCAN cursor [MATCH pattern] [COUNT n] [TYPE type] Incrementally iterate keys; safe alternative to KEYS.

Strings

Command Description
GET key Return the string value of a key.
SET key value [NX|XX] [EX seconds|PX ms|EXAT|PXAT] [GET] Set a string value with optional existence and TTL options.
GETEX key [EX|PX|EXAT|PXAT] [PERSIST] Get value and optionally refresh or remove TTL.
MGET key [key ...] Get multiple string values in one round trip.
MSET key value [key value ...] Set multiple string values atomically.
INCR key Increment an integer string by 1; errors if value is not an integer.
INCRBY key increment Increment an integer string by increment.
INCRBYFLOAT key increment Increment a floating-point string by increment.
DECR key Decrement an integer string by 1.

Lists

Command Description
LPUSH key element [element ...] Prepend one or more elements to a list.
RPUSH key element [element ...] Append one or more elements to a list.
LPOP key [count] Remove and return element(s) from the head.
RPOP key [count] Remove and return element(s) from the tail.
BLPOP key [key ...] timeout Blocking pop from the head; waits up to timeout seconds.
BRPOP key [key ...] timeout Blocking pop from the tail; waits up to timeout seconds.
LRANGE key start stop Return a range of elements by index (0-based, negative = from end).
LLEN key Return the length of a list.
LTRIM key start stop Trim the list to the specified index range.
LMOVE source dest LEFT|RIGHT LEFT|RIGHT Atomically move an element between two lists.

Sets

Command Description
SADD key member [member ...] Add one or more members to a set.
SREM key member [member ...] Remove one or more members from a set.
SMEMBERS key Return all members of a set (O(N); use SSCAN for large sets).
SISMEMBER key member Return 1 if member exists in the set, 0 otherwise.
SMISMEMBER key member [member ...] Batch membership test for multiple members.
SCARD key Return the number of members in a set.
SPOP key [count] Remove and return random member(s).
SINTER key [key ...] Return the intersection of multiple sets.
SUNION key [key ...] Return the union of multiple sets.
SDIFF key [key ...] Return members in the first set not present in the others.
SSCAN key cursor [MATCH pattern] [COUNT n] Incrementally iterate set members.

Hashes

Command Description
HSET key field value [field value ...] Set one or more hash fields (creates key if needed).
HGET key field Return the value of a hash field.
HMGET key field [field ...] Return values for multiple fields.
HGETALL key Return all field-value pairs (O(N); prefer HSCAN for large hashes).
HDEL key field [field ...] Delete one or more hash fields.
HEXISTS key field Return 1 if the field exists, 0 otherwise.
HLEN key Return the number of fields in a hash.
HINCRBY key field increment Increment an integer field by increment.
HINCRBYFLOAT key field increment Increment a float field by increment.
HSCAN key cursor [MATCH pattern] [COUNT n] Incrementally iterate hash fields.

Sorted Sets

Command Description
ZADD key [NX|XX] [GT|LT] [CH] score member [score member ...] Add members with scores; supports conditional and changed-reply modes.
ZREM key member [member ...] Remove one or more members from a sorted set.
ZSCORE key member Return the score of a member.
ZRANK key member Return rank (0-based, lowest score first).
ZRANGE key start stop [BYSCORE|BYLEX] [REV] [LIMIT offset count] [WITHSCORES] Return members by rank, score, or lex range.
ZCOUNT key min max Count members with scores between min and max.
ZCARD key Return the number of members in a sorted set.
ZINCRBY key increment member Increment a member's score by increment.
ZPOPMIN key [count] Remove and return member(s) with the lowest scores.
BZPOPMIN key [key ...] timeout Blocking pop of lowest-score member(s).

Streams

Command Description
XADD key [NOMKSTREAM] [MAXLEN|MINID [=|~] threshold] *|ID field value [field value ...] Append an entry; auto-generate ID with *.
XREAD [COUNT count] [BLOCK ms] STREAMS key [key ...] id [id ...] Read entries from one or more streams (use $ for new entries only).
XRANGE key start end [COUNT count] Read entries in ID order within a range.
XLEN key Return the number of entries in a stream.
`XTRIM key MAXLEN|MINID [= ~] threshold [LIMIT count]`
XGROUP CREATE key groupname id [MKSTREAM] Create a consumer group anchored at id ($ = only new entries).
XREADGROUP GROUP group consumer [COUNT n] [BLOCK ms] [NOACK] STREAMS key [key ...] id [id ...] Read entries as a consumer group member.
XACK key group id [id ...] Acknowledge processed entries in a consumer group.
XPENDING key group [start end count] [consumer] List pending (delivered but unacknowledged) entries.
XCLAIM key group consumer min-idle-time id [id ...] [IDLE ms] [FORCE] Claim stale pending messages for another consumer.
XINFO STREAM key Return metadata about a stream (length, groups, etc.).

Geospatial

Command Description
GEOADD key [NX|XX] [CH] longitude latitude member [...] Add geospatial locations to a sorted set.
GEOPOS key member [member ...] Return longitude/latitude for members.
GEODIST key member1 member2 [m|km|ft|mi] Return distance between two members.
GEOSEARCH key [FROMMEMBER member|FROMLONLAT lon lat] [BYRADIUS radius unit|BYBOX w h unit] [ASC|DESC] [COUNT count] Search locations within a radius or bounding box. (7.0+)
GEOSEARCHSTORE dest source ... Store geosearch results in a destination key. (7.0+)

Pub/Sub

Command Description
PUBLISH channel message Send a message to all subscribers of a channel.
SUBSCRIBE channel [channel ...] Subscribe to channels (blocking connection mode).
UNSUBSCRIBE [channel [channel ...]] Unsubscribe from channels or all if none specified.
PSUBSCRIBE pattern [pattern ...] Subscribe to channels matching glob patterns.
PUBSUB CHANNELS [pattern] List active channels (optionally matching a pattern).
PUBSUB NUMSUB [channel ...] Return subscriber counts for channels.

Bitmaps & HyperLogLog

Command Description
SETBIT key offset value Set or clear a bit at offset (creates key if needed).
GETBIT key offset Return the bit value at offset.
BITCOUNT key [start end] Count set bits in a string or range.
PFADD key element [element ...] Add elements to a HyperLogLog (approximate cardinality).
PFCOUNT key [key ...] Estimate cardinality of one or more HyperLogLog keys.

Transactions & Scripting

Command Description
MULTI Start a transaction; subsequent commands are queued.
EXEC Execute all queued commands atomically.
DISCARD Discard all queued commands.
WATCH key [key ...] Watch keys for changes; aborts transaction if any key is modified before EXEC.
EVAL script numkeys key [key ...] arg [arg ...] Run a Lua script with keys and arguments.
FCALL function numkeys key [key ...] arg [arg ...] Invoke a Redis Function by name. (7.0+)

Server Administration

Command Description
PING [message] Test connectivity; returns PONG or echoes the message.
DBSIZE Return the number of keys in the current database.
INFO [section] Return server statistics (memory, replication, stats, all, etc.).
CONFIG GET parameter Read a configuration parameter at runtime.
CONFIG SET parameter value Set a runtime configuration parameter (not all directives are mutable).
CLIENT LIST [TYPE type] [ID id] List connected clients with metadata.
CLIENT KILL ip:port|ID id|ADDR addr|... Disconnect matching clients.
SLOWLOG GET [count] Return recent slow commands from the slow log.
MEMORY STATS Return detailed memory usage breakdown.
BGSAVE [SCHEDULE] Fork a background RDB save process.
FLUSHDB [ASYNC|SYNC] Delete all keys in the current database.
FLUSHALL [ASYNC|SYNC] Delete all keys in all databases.
SHUTDOWN [SAVE|NOSAVE] [NOW|FORCE|ABORT] Stop the server gracefully or forcefully.
ROLE Return replication role (master, slave, sentinel) and offset info.
REPLICAOF host port Configure this instance as a replica of host:port (use REPLICAOF NO ONE to promote).

Cluster

Command Description
CLUSTER INFO Return cluster state summary (slots assigned, failover state, etc.).
CLUSTER NODES Return node ID, address, role, slots, and link status for all nodes.
CLUSTER MEET ip port Join a node to the cluster by greeting it at ip:port.
CLUSTER REPLICATE node-id Configure the current node as a replica of node-id.
CLUSTER FAILOVER [FORCE|TAKEOVER] Trigger manual or forced failover for the current primary.
CLUSTER KEYSLOT key Return the hash slot (0–16383) for a key.

ACL & Security

Command Description
ACL LIST Return all ACL rules in ACL file format.
ACL SETUSER username [rule ...] Create or modify a user with permission rules.
ACL GETUSER username Return rules and metadata for a user.
ACL DELUSER username [username ...] Delete one or more ACL users.
ACL WHOAMI Return the username of the current connection.
ACL LOAD Reload ACL rules from aclfile.
ACL SAVE Save current ACL rules to aclfile.
AUTH [username] password Authenticate the connection (username required when ACL users are enabled).

Quick Tips

  • Pipelining is a client feature, not a command—batch commands without waiting for each reply to cut latency.
  • Blocking commands (BLPOP, XREAD BLOCK, BZPOPMIN, etc.) hold a connection; size connection pools accordingly.
  • In Cluster, multi-key commands require all keys to hash to the same slot—use hash tags ({user}:profile, {user}:sessions).
  • Use SCAN family (SCAN, HSCAN, SSCAN, ZSCAN) instead of KEYS or full SMEMBERS/HGETALL on large collections.
  • Avoid MONITOR and KEYS * in production—they block or scan the entire keyspace.

Back to: Table of Contents · Next: Appendix B — Configuration Reference →

See also: Chapter 24 — Troubleshooting & Observability · Redis Command Reference