API reference
Redis API reference
Redis caching and data structures
- Identifiers
- 141
- With full guides
- 59
- Types
- 4
Topics covered
- Strings & TTL
- Hashes & lists
- Sets & sorted sets
- Pub/Sub
- Caching patterns
- Rate limiting
- Streams
- Persistence
Function
| Name | What it does |
|---|---|
createClient | createClient creates a node-redis client configured for Redis, defaulting to localhost on port 6379. Supply options such as a connection URL for another server, then connect explicitly before using commands. |
Const
| Name | What it does |
|---|---|
String | |
Hash | |
List | |
Set | |
Sorted Set | |
Stream | |
Bitmap | |
HyperLogLog | |
Geospatial | |
Bloom filter |
Module
| Name | What it does |
|---|---|
GETSET | GETSET atomically replaces a key's string value and returns the value previously stored there. It is deprecated since Redis 6.2.0; new code should use SET with GET. |
GETDEL | GETDEL returns a string value and deletes its key in the same command. It returns nil when the key is missing or does not contain a string. |
MSET | MSET atomically assigns string values to one or more keys in a single command. Existing values are overwritten, and a successful command returns OK. |
MGET | MGET atomically retrieves the string values of one or more keys in a single command. Missing keys and keys holding non-string values return nil in their corresponding result positions. |
DECR | Decrements the integer value stored at a key by one and returns the updated value. If the key is missing, Redis starts from zero. |
INCRBY | INCRBY adds an integer increment to a key's integer value and returns the updated value. Missing keys begin at zero, while wrong types, non-integer strings, and out-of-range values cause errors. |
DECRBY | DECRBY subtracts an integer amount from a key's stored integer value and returns the updated value. Missing keys start at zero, while non-integer values and out-of-range results cause errors. |
INCRBYFLOAT | Adds a floating-point number to the numeric string stored at a Redis key and returns the updated value as a string. Missing keys start at zero, and negative increments decrement the value. |
APPEND | APPEND adds a string to the end of a key's existing string value, creating the key if it is missing. It returns the resulting string length. |
STRLEN | Returns the length of the string value stored at a key. Missing keys return 0, while keys holding non-string values cause an error. |
SETNX | Sets a string value only when a key does not already exist. It returns 1 when the key is created and 0 when no write occurs; SET with NX is the recommended replacement for new code. |
SETRANGE | Overwrites part of a Redis string from a specified zero-based offset. It pads with zero bytes when necessary and returns the string's resulting length. |
GETRANGE | Returns a substring of the Redis string stored at a key, using inclusive zero-based start and end offsets. Negative offsets count backward from the string's end. |
EXISTS | EXISTS determines whether one or more Redis keys exist and returns the number found. It can check multiple keys in one command. |
PEXPIRE | Sets a key's expiration timeout in milliseconds. Optional NX, XX, GT, and LT modes conditionally control whether the timeout is applied. |
PTTL | Returns the remaining expiration time of a key in milliseconds. It distinguishes an existing key without expiration (-1) from a missing key (-2). |
TYPE | TYPE reports the Redis data type stored at a key. It returns none when the key does not exist. |
RANDOMKEY | |
TOUCH | TOUCH updates the last-access time of each supplied key that exists and returns how many supplied keys were found. It does not alter key values. |
UNLINK | UNLINK asynchronously deletes one or more Redis keys. It removes keys from the keyspace promptly while reclaiming their memory in a background thread. |
DUMP | Returns a Redis-specific serialized representation of the value stored at a key. The result can be used with RESTORE, but does not include expiration information. |
RESTORE | RESTORE creates a key by deserializing a serialized value produced by DUMP. It can apply a relative or absolute expiration and optionally replace an existing key or initialize eviction metadata. |
COPY | Copies the value of one Redis key to another key. It can target a different logical database and optionally replace an existing destination. |
HGET | Returns the value of one field in a Redis hash. If the field or its hash key does not exist, Redis returns nil/null. |
HMGET | Returns the values of multiple fields from a Redis hash, preserving field order and representing missing fields with nil. |
HEXISTS | Checks whether a field exists in a Redis hash. It returns 1 for an existing field and 0 when the field or hash key is absent. |
HKEYS | HKEYS returns all field names in the hash stored at a key. It returns an empty list when the key does not exist and has O(N) complexity based on the hash size. |
HVALS | Returns all values stored in a Redis hash. Use it when field names are unnecessary; the result order is not guaranteed. |
HLEN | HLEN returns the number of fields in a Redis hash. It runs in O(1) time and returns 0 when the key does not exist. |
HINCRBY | HINCRBY adds a signed integer to a field in a Redis hash and returns the updated value. Missing hashes and fields are created automatically, with a missing field starting at zero. |
HSCAN | HSCAN incrementally iterates through the fields of a Redis hash. It supports glob matching, a COUNT hint, and NOVALUES for returning field names without values. |
HRANDFIELD | Returns one or more randomly selected fields from a hash. Positive counts select distinct fields up to the hash size; negative counts allow repeats, and WITHVALUES also returns the selected values. |
RPOP | |
LLEN | |
LINDEX | |
LSET | |
LINSERT | |
LREM | |
LTRIM | |
BLPOP | |
BRPOP | |
LMOVE | |
LPOS | |
SADD | |
SREM | |
SISMEMBER | |
SCARD | |
SPOP | |
SRANDMEMBER | |
SUNION | |
SINTER | |
SDIFF | |
SSCAN | |
SMISMEMBER | |
ZREM | |
ZRANGEBYSCORE | |
ZREVRANGE | |
ZSCORE | |
ZRANK | |
ZREVRANK | |
ZCARD | |
ZCOUNT | |
ZINCRBY | |
ZPOPMIN | |
ZPOPMAX | |
PSUBSCRIBE | |
UNSUBSCRIBE | |
XADD | |
XREAD | |
XRANGE | |
XLEN | |
XGROUP | |
XREADGROUP | |
XACK | |
XTRIM | |
EXEC | |
DISCARD | |
WATCH | |
UNWATCH | |
EVAL | |
EVALSHA | |
SCRIPT | |
FUNCTION | |
FCALL | |
PING | |
INFO | |
CONFIG | |
DBSIZE | |
FLUSHALL | |
CLIENT | |
COMMAND | |
MEMORY | |
GEOADD | |
GEOSEARCH | |
SETBIT | |
GETBIT | |
BITCOUNT | |
PFADD | |
PFCOUNT | |
PFMERGE | |
AUTH | |
SELECT | |
HELLO |
Command
| Name | What it does |
|---|---|
GET | GET returns the string value stored at a key. It returns nil for a missing key and errors when the key contains a non-string value. |
SET | Sets a key to a string, creating it or replacing its current value. Conditions, expiration controls, and GET support conditional writes, lifetimes, and retrieval of the previous string. |
HSET | Creates or updates one or more fields in a Redis hash. It returns how many fields were newly added, excluding fields whose existing values were overwritten. |
LPUSH | LPUSH prepends one or more elements to a Redis list, creating the list when the key is absent. It returns the list's length after insertion. |
ZADD | Adds members with scores to a sorted set, updating existing members and creating the key when needed. Options can restrict updates, count changed entries, or increment one member's score. |
EXPIRE | Sets a relative expiration timeout, in seconds, on a key. When the timeout elapses, Redis automatically deletes the key. |
SUBSCRIBE | Subscribes the client to one or more exact channel names. Redis then pushes matching published messages and subscription confirmations through that connection. |
MULTI | MULTI starts a Redis transaction and queues later commands on the current connection. EXEC runs the queued commands atomically, while DISCARD cancels them. |
INCR | Increments the integer stored at a key by one. A missing key starts at zero, so the first call returns one. |
DEL | DEL removes one or more specified keys and ignores names that do not exist. It returns the count of keys successfully deleted. |
HGETALL | Returns every field and value in the hash stored at a key. The operation is O(N), where N is the number of fields. |
LRANGE | Returns an inclusive range of elements from a Redis list. Start and stop use zero-based indexes, and negative indexes count from the list's tail. |
SMEMBERS | Returns every member of the set stored at a key. The result contains the set's complete, unordered membership. |
ZRANGE | Returns members from a sorted set selected by rank, score, or lexicographical range. Optional reverse ordering, pagination, and score output support ranking, filtering, and windowed reads. |
TTL | Returns a key's remaining expiration time in seconds. It distinguishes missing keys from existing keys that have no expiration. |
KEYS | Returns every key name matching a glob-style pattern. Because it can block the Redis server while producing the complete result, reserve it for debugging and exceptional administrative tasks. |
SCAN | SCAN incrementally iterates over key names in the currently selected Redis database. Continue with each returned cursor until it becomes 0, optionally filtering by pattern, count hint, or type. |
PUBLISH | PUBLISH sends a message to a channel for delivery to its current subscribers. It returns the number of clients that received the message. |
FLUSHDB | FLUSHDB removes all keys from the currently selected Redis database. Use ASYNC or SYNC to choose asynchronous or synchronous flushing. |
GETEX | Returns a string value while optionally setting, changing, or removing the key's expiration. GETEX supports relative and absolute expiration forms and is a write command. |
SETEX | SETEX stores a string at a key and gives it a timeout in seconds. It is deprecated in favor of SET with the EX option. |
HDEL | HDEL deletes one or more fields from a Redis hash. It ignores missing fields, removes the hash when no fields remain, and returns the number of fields actually deleted. |
LPOP | Removes and returns elements from the beginning of a Redis list. It removes one element by default or up to count elements when count is supplied. |
RPUSH | Appends one or more values to the tail of a Redis list, creating the key when absent. It returns the list's new length. |
EXPIREAT | Sets a key's expiration to an absolute Unix timestamp in seconds. Optional NX, XX, GT, or LT conditions control when the deadline may be changed. |
PERSIST | Removes the existing expiration from a key, making it persistent. Returns 1 when a timeout was removed, otherwise 0. |
RENAME | Renames a key to a new name, replacing the destination if it already exists. In Redis Cluster, both names must belong to the same hash slot. |
Search across every package and filter by type in your dashboard.
Start learning