title: MSETNX

summary: Atomically modifies the string values of one or more keys only when all keys don't exist.

title: Overview

text:
This command's behavior varies in clustered Redis environments. See the [multi-key operations]() page for more information.

Sets the given keys to their respective values.
`MSETNX` will not perform any operation at all even if just a single key already
exists.

Because of this semantic `MSETNX` can be used in order to set different keys
representing different fields of a unique logic object in a way that ensures
that either all the fields or none at all are set.

`MSETNX` is atomic, so all given keys are set at once.
It is not possible for clients to see that some of the keys were updated while
others are unchanged.

title: Examples

text:
MSETNX key1 "Hello" key2 "there"
MSETNX key2 "new" key3 "world"
MGET key1 key2 key3

title: Return information

text:
**RESP2:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if no key was set (at least one key already existed).
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if all the keys were set.

**RESP3:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if no key was set (at least one key already existed).
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if all the keys were set.


title: MULTI

summary: Starts a transaction.

page_type: content

title: Overview

role: overview

text:
This command's behavior varies in clustered Redis environments. See the [multi-key operations]() page for more information.

Marks the start of a [transaction][tt] block.
Subsequent commands will be queued for atomic execution using [`EXEC`]().

[tt]: /develop/interact/transactions

title: Redis Software and Redis Cloud compatibility

role: content

text:
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ✅ Standard
<nobr>✅ Active-Active</nobr> | ✅ Standard
<nobr>✅ Active-Active</nobr> |  |

title: Return information

role: returns

text:
**RESP2:**

[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.

**RESP3:**

[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.


title: OBJECT

summary: A container for object introspection commands.

title: Content

text:
This is a container command for object introspection commands.

To see the list of available commands you can call [`OBJECT HELP`]().


title: OBJECT ENCODING

summary: Returns the internal encoding of a Redis object.

title: Overview

text:
Returns the internal encoding for the Redis object stored at `<key>`

Redis objects can be encoded in different ways:

* Strings can be encoded as:

    - `raw`, normal string encoding.
    - `int`, strings representing integers in a 64-bit signed interval, encoded in this way to save space.
    - `embstr`, an embedded string, which is an object where the internal simple dynamic string, `sds`, is an unmodifiable string allocated in the same chuck as the object itself.
      `embstr` can be strings with lengths up to the hardcoded limit of `OBJ_ENCODING_EMBSTR_SIZE_LIMIT` or 44 bytes.

* Lists can be encoded as:

    - `linkedlist`, simple list encoding. No longer used, an old list encoding.
    - `ziplist`, Redis <= 6.2, a space-efficient encoding used for small lists.
    - `listpack`, Redis >= 7.0, a space-efficient encoding used for small lists.
    - `quicklist`, encoded as linkedlist of ziplists or listpacks.

* Sets can be encoded as:

    - `hashtable`, normal set encoding.
    - `intset`, a special encoding used for small sets composed solely of integers.
    - `listpack`, Redis >= 7.2, a space-efficient encoding used for small sets.

* Hashes can be encoded as:

    - `zipmap`, no longer used, an old hash encoding.
    - `hashtable`, normal hash encoding.
    - `ziplist`, Redis <= 6.2, a space-efficient encoding used for small hashes.
    - `listpack`, Redis >= 7.0, a space-efficient encoding used for small hashes.

* Sorted Sets can be encoded as:

    - `skiplist`, normal sorted set encoding.
    - `ziplist`, Redis <= 6.2, a space-efficient encoding used for small sorted sets.
    - `listpack`, Redis >= 7.0, a space-efficient encoding used for small sorted sets.

* Streams can be encoded as:

  - `stream`, encoded as a radix tree of listpacks.

All the specially encoded types are automatically converted to the general type once you perform an operation that makes it impossible for Redis to retain the space saving encoding.

text:
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ✅ Standard
<nobr>❌ Active-Active</nobr> | ✅ Standard
<nobr>❌ Active-Active</nobr> | For Active-Active databases, use `CRDT.DEBUG ENCODING` instead. |

title: Return information

text:
**RESP2:**

One of the following:
* [Nil reply](../../develop/reference/protocol-spec#bulk-strings): if the key doesn't exist.
* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): the encoding of the object.

**RESP3:**

One of the following:
* [Null reply](../../develop/reference/protocol-spec#nulls): if the key doesn't exist.
* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): the encoding of the object.


title: OBJECT FREQ

summary: Returns the logarithmic access frequency counter of a Redis object.

title: Overview

text:
This command returns the logarithmic access frequency counter of a Redis object stored at `<key>`.

The command is only available when the `maxmemory-policy` configuration directive is set to one of the LFU policies.

title: Return information

text:
**RESP2:**

One of the following:
[Integer reply](../../develop/reference/protocol-spec#integers): the counter's value.
[Nil reply](../../develop/reference/protocol-spec#bulk-strings): if _key_ doesn't exist.

**RESP3:**

One of the following:
[Integer reply](../../develop/reference/protocol-spec#integers): the counter's value.
[Null reply](../../develop/reference/protocol-spec#nulls): if _key_ doesn't exist.


title: OBJECT HELP

summary: Returns helpful text about the different subcommands.

title: Overview

text: The `OBJECT HELP` command returns a helpful text describing the different subcommands.

text:
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ❌ Standard
<nobr>❌ Active-Active</nobr> | ❌ Standard
<nobr>❌ Active-Active</nobr> |  |

title: Return information

text:
**RESP2:**

[Array reply](../../develop/reference/protocol-spec#arrays): a list of sub-commands and their descriptions

**RESP3:**

[Array reply](../../develop/reference/protocol-spec#arrays): a list of sub-commands and their descriptions.


title: OBJECT IDLETIME

summary: Returns the time since the last access to a Redis object.

title: Overview

text:
This command returns the time in seconds since the last access to the value stored at `<key>`.

The command is only available when the `maxmemory-policy` configuration directive is not set to one of the LFU policies.

title: Return information

text:
**RESP2:**

One of the following:
[Integer reply](../../develop/reference/protocol-spec#integers): the idle time in seconds.
[Nil reply](../../develop/reference/protocol-spec#bulk-strings): if _key_ doesn't exist.

**RESP3:**

One of the following:
[Integer reply](../../develop/reference/protocol-spec#integers): the idle time in seconds.
[Null reply](../../develop/reference/protocol-spec#nulls): if _key_ doesn't exist.


title: OBJECT REFCOUNT

summary: Returns the reference count of a value of a key.

title: Overview

text: This command returns the reference count of the stored at `<key>`.

title: Return information

text:
**RESP2:**

One of the following:
[Integer reply](../../develop/reference/protocol-spec#integers): the number of references.
[Nil reply](../../develop/reference/protocol-spec#bulk-strings): if _key_ doesn't exist.

**RESP3:**

One of the following:
[Integer reply](../../develop/reference/protocol-spec#integers): the number of references.
[Null reply](../../develop/reference/protocol-spec#nulls): if _key_ doesn't exist.


title: PERSIST

summary: Removes the expiration time of a key.

title: Overview

text:
Remove the existing timeout on `key`, turning the key from _volatile_ (a key
with an expire set) to _persistent_ (a key that will never expire as no timeout
is associated).

title: Examples

role: example

text:
SET mykey "Hello"
EXPIRE mykey 10
TTL mykey
PERSIST mykey
TTL mykey

title: Return information

text:
**RESP2:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if _key_ does not exist or does not have an associated timeout.
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if the timeout has been removed.

**RESP3:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if _key_ does not exist or does not have an associated timeout.
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if the timeout has been removed.


title: PEXPIRE

summary: Sets the expiration time of a key in milliseconds.

title: Overview

text:
This command works exactly like [`EXPIRE`]() but the time to live of the key is
specified in milliseconds instead of seconds.

title: Options

role: parameters

text:
The `PEXPIRE` command supports a set of options since Redis 7.0:

* `NX` -- Set expiry only when the key has no expiry
* `XX` -- Set expiry only when the key has an existing expiry
* `GT` -- Set expiry only when the new expiry is greater than current one
* `LT` -- Set expiry only when the new expiry is less than current one

A non-volatile key is treated as an infinite TTL for the purpose of `GT` and `LT`.
The `GT`, `LT` and `NX` options are mutually exclusive.

title: Examples

text:
SET mykey "Hello"
PEXPIRE mykey 1500
TTL mykey
PTTL mykey
PEXPIRE mykey 1000 XX
TTL mykey
PEXPIRE mykey 1000 NX
TTL mykey

text:
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ✅ Standard
<nobr>✅ Active-Active</nobr> | ✅ Standard
<nobr>✅ Active-Active</nobr> |  |

title: Return information

text:
**RESP2:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if the timeout was not set. For example, if the key doesn't exist, or the operation skipped because of the provided arguments.
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if the timeout was set.

**RESP3:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if the timeout was not set. For example, if the key doesn't exist, or the operation skipped because of the provided arguments.
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if the timeout was set.


title: PEXPIREAT

summary: Sets the expiration time of a key to a Unix milliseconds timestamp.

title: Overview

text:
`PEXPIREAT` has the same effect and semantic as [`EXPIREAT`](), but the Unix time at
which the key will expire is specified in milliseconds instead of seconds.

title: Options

text:
The `PEXPIREAT` command supports a set of options since Redis 7.0:

* `NX` -- Set expiry only when the key has no expiry
* `XX` -- Set expiry only when the key has an existing expiry
* `GT` -- Set expiry only when the new expiry is greater than current one
* `LT` -- Set expiry only when the new expiry is less than current one

A non-volatile key is treated as an infinite TTL for the purpose of `GT` and `LT`.
The `GT`, `LT` and `NX` options are mutually exclusive.

title: Examples

text:
SET mykey "Hello"
PEXPIREAT mykey 1555555555005
TTL mykey
PTTL mykey

title: Return information

text:
**RESP2:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if the timeout was set.
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if the timeout was not set. For example, if the key doesn't exist, or the operation was skipped due to the provided arguments.

**RESP3:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if the timeout was set.
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if the timeout was not set. For example, if the key doesn't exist, or the operation was skipped due to the provided arguments.


title: PEXPIRETIME

summary: Returns the expiration time of a key as a Unix milliseconds timestamp.

title: Overview

text: `PEXPIRETIME` has the same semantic as [`EXPIRETIME`](), but returns the absolute Unix expiration timestamp in milliseconds instead of seconds.

title: Examples

text:
SET mykey "Hello"
PEXPIREAT mykey 33177117420000
PEXPIRETIME mykey

title: Return information

text:
**RESP2:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): Expiration Unix timestamp in milliseconds.
* [Integer reply](../../develop/reference/protocol-spec#integers): `-1` if the key exists but has no associated expiration time.
* [Integer reply](../../develop/reference/protocol-spec#integers): `-2` if the key does not exist.

**RESP3:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): Expiration Unix timestamp in milliseconds.
* [Integer reply](../../develop/reference/protocol-spec#integers): `-1` if the key exists but has no associated expiration time.
* [Integer reply](../../develop/reference/protocol-spec#integers): `-2` if the key does not exist.


title: PFADD

summary: Adds elements to a HyperLogLog key. Creates the key if it doesn't exist.

title: Overview

text:
Adds all the element arguments to the HyperLogLog data structure stored at the variable name specified as first argument.

As a side effect of this command the HyperLogLog internals may be updated to reflect a different estimation of the number of unique items added so far (the cardinality of the set).

If the approximated cardinality estimated by the HyperLogLog changed after executing the command, `PFADD` returns 1, otherwise 0 is returned. The command automatically creates an empty HyperLogLog structure (that is, a Redis String of a specified length and with a given encoding) if the specified key does not exist.

To call the command without elements but just the variable name is valid, this will result into no operation performed if the variable already exists, or just the creation of the data structure if the key does not exist (in the latter case 1 is returned).

For an introduction to HyperLogLog data structure check the [`PFCOUNT`]() command page.

title: Examples

text:
PFADD hll a b c d e f g
PFCOUNT hll

title: Return information

text:
**RESP2:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if at least one HyperLogLog internal register was altered.
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if no HyperLogLog internal registers were altered.

**RESP3:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if at least one HyperLogLog internal register was altered.
* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if no HyperLogLog internal registers were altered.


title: PFCOUNT

summary: Returns the approximated cardinality of the set(s) observed by the HyperLogLog key(s).

title: Overview

text:
This command's behavior varies in clustered Redis environments. See the [multi-key operations]() page for more information.

When called with a single key, returns the approximated cardinality computed by the HyperLogLog data structure stored at the specified variable, which is 0 if the variable does not exist.

When called with multiple keys, returns the approximated cardinality of the union of the HyperLogLogs passed, by internally merging the HyperLogLogs stored at the provided keys into a temporary HyperLogLog.

The HyperLogLog data structure can be used in order to count **unique** elements in a set using just a small constant amount of memory, specifically 12k bytes for every HyperLogLog (plus a few bytes for the key itself).

The returned cardinality of the observed set is not exact, but approximated with a standard error of 0.81%.

For example in order to take the count of all the unique search queries performed in a day, a program needs to call [`PFADD`]() every time a query is processed. The estimated number of unique queries can be retrieved with `PFCOUNT` at any time.

Note: as a side effect of calling this function, it is possible that the HyperLogLog is modified, since the last 8 bytes encode the latest computed cardinality
for caching purposes. So `PFCOUNT` is technically a write command.

title: Examples

text:
PFADD hll foo bar zap
PFADD hll zap zap zap
PFADD hll foo bar
PFCOUNT hll
PFADD some-other-hll 1 2 3
PFCOUNT hll some-other-hll

Performances
---

When `PFCOUNT` is called with a single key, performances are excellent even if
in theory constant times to process a dense HyperLogLog are high. This is
possible because the `PFCOUNT` uses caching in order to remember the cardinality
previously computed, that rarely changes because most [`PFADD`]() operations will
not update any register. Hundreds of operations per second are possible.

When `PFCOUNT` is called with multiple keys, an on-the-fly merge of the
HyperLogLogs is performed, which is slow, moreover the cardinality of the union
can't be cached, so when used with multiple keys `PFCOUNT` may take a time in
the order of magnitude of the millisecond, and should be not abused.

The user should take in mind that single-key and multiple-keys executions of
this command are semantically different and have different performances.

HyperLogLog representation
---

Redis HyperLogLogs are represented using a double representation: the *sparse* representation suitable for HLLs counting a small number of elements (resulting in a small number of registers set to non-zero value), and a *dense* representation suitable for higher cardinalities. Redis automatically switches from the sparse to the dense representation when needed.

The sparse representation uses a run-length encoding optimized to store efficiently a big number of registers set to zero. The dense representation is a Redis string of 12288 bytes in order to store 16384 6-bit counters. The need for the double representation comes from the fact that using 12k (which is the dense representation memory requirement) to encode just a few registers for smaller cardinalities is extremely suboptimal.

Both representations are prefixed with a 16 bytes header, that includes a magic, an encoding / version field, and the cached cardinality estimation computed, stored in little endian format (the most significant bit is 1 if the estimation is invalid since the HyperLogLog was updated since the cardinality was computed).

The HyperLogLog, being a Redis string, can be retrieved with [`GET`]() and restored with [`SET`](). Calling [`PFADD`](), `PFCOUNT` or [`PFMERGE`]() commands with a corrupted HyperLogLog is never a problem, it may return random values but does not affect the stability of the server. Most of the times when corrupting a sparse representation, the server recognizes the corruption and returns an error.

The representation is neutral from the point of view of the processor word size and endianness, so the same representation is used by 32 bit and 64 bit processor, big endian or little endian.

More details about the Redis HyperLogLog implementation can be found in [this blog post](http://antirez.com/news/75). The source code of the implementation in the `hyperloglog.c` file is also easy to read and understand, and includes a full specification for the exact encoding used for the sparse and dense representations.

title: Return information

text:
**RESP2:**

[Integer reply](../../develop/reference/protocol-spec#integers): the approximated number of unique elements observed via `PFADD`.

**RESP3:**

[Integer reply](../../develop/reference/protocol-spec#integers): the approximated number of unique elements observed via `PFADD`


title: PFDEBUG

summary: Internal commands for debugging HyperLogLog values.

title: Content

text:
The `PFDEBUG` command is an internal command.
It is meant to be used for developing and testing Redis.


title: PFMERGE

summary: Merges one or more HyperLogLog values into a single key.

title: Overview

text:
This command's behavior varies in clustered Redis environments. See the [multi-key operations]() page for more information.

Merge multiple HyperLogLog values into a unique value that will approximate
the cardinality of the union of the observed Sets of the source HyperLogLog
structures.

The computed merged HyperLogLog is set to the destination variable, which is
created if does not exist (defaulting to an empty HyperLogLog).

If the destination variable exists, it is treated as one of the source sets
and its cardinality will be included in the cardinality of the computed
HyperLogLog.

title: Examples

text:
PFADD hll1 foo bar zap a
PFADD hll2 a b c foo
PFMERGE hll3 hll1 hll2
PFCOUNT hll3

title: Return information

text:
**RESP2:**

[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.

**RESP3:**

[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.


title: PFSELFTEST

summary: An internal command for testing HyperLogLog values.

title: Overview

text:
The `PFSELFTEST` command is an internal command.
It is meant to be used for developing and testing Redis.

text:
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ❌ Standard
<nobr>❌ Active-Active</nobr> | ❌ Standard
<nobr>❌ Active-Active</nobr> |  |

title: Return information


title: PING

summary: Returns the server's liveliness response.

title: Overview

text:
Returns `PONG` if no argument is provided, otherwise return a copy of the
argument as a bulk.
This command is useful for:
1. Testing whether a connection is still alive.
1. Verifying the server's ability to serve data - an error is returned when this isn't the case (e.g., during load from persistence or accessing a stale replica).
1. Measuring latency.

If the client is subscribed to a channel or a pattern, it will instead return a
multi-bulk with a "pong" in the first position and an empty bulk in the second
position, unless an argument is provided in which case it returns a copy
of the argument.

title: Examples

text:
PING

PING "hello world"

text:
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ✅ Standard
<nobr>✅ Active-Active</nobr> | ✅ Standard
<nobr>✅ Active-Active</nobr> |  |

title: Return information

text:
**RESP2:**

Any of the following:
* [Simple string reply](../../develop/reference/protocol-spec#simple-strings): `PONG` when no argument is provided.
* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): the provided argument.

**RESP3:**

Any of the following:
* [Simple string reply](../../develop/reference/protocol-spec#simple-strings): `PONG` when no argument is provided.
* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): the provided argument.


title: PSETEX

summary: Sets both string value and expiration time in milliseconds of a key. The key is created if it doesn't exist.

title: Overview

text:
`PSETEX` works exactly like [`SETEX`]() with the sole difference that the expire
time is specified in milliseconds instead of seconds.

title: Examples

text:
PSETEX mykey 1000 "Hello"
PTTL mykey
GET mykey

title: Return information


title: PSUBSCRIBE

summary: Listens for messages published to channels that match one or more patterns.

title: Overview

text:
Subscribes the client to the given patterns.

Supported glob-style patterns:

* `h?llo` subscribes to `hello`, `hallo` and `hxllo`
* `h*llo` subscribes to `hllo` and `heeeello`
* `h[ae]llo` subscribes to `hello` and `hallo,` but not `hillo`

Use `\` to escape special characters if you want to match them verbatim.

Once the client enters the subscribed state it is not supposed to issue any other commands, except for additional [`SUBSCRIBE`](), [`SSUBSCRIBE`](), `PSUBSCRIBE`, [`UNSUBSCRIBE`](), [`SUNSUBSCRIBE`](), [`PUNSUBSCRIBE`](), [`PING`](), [`RESET`]() and [`QUIT`]() commands.
However, if RESP3 is used (see [`HELLO`]()) it is possible for a client to issue any commands while in subscribed state.

For more information, see [Pub/sub]().

title: Behavior change history

text: *   `>= 6.2.0`: [`RESET`]() can be called to exit subscribed state.

title: Return information

text:
**RESP2:**

When successful, this command doesn't return anything. Instead, for each pattern, one message with the first element being the string `psubscribe` is pushed as a confirmation that the command succeeded.

**RESP3:**

When successful, this command doesn't return anything. Instead, for each pattern, one message with the first element being the string `psubscribe` is pushed as a confirmation that the command succeeded.


title: PSYNC

summary: An internal command used in replication.

title: Overview

text:
Initiates a replication stream from the master.

The `PSYNC` command is called by Redis replicas for initiating a replication
stream from the master.

For more information about replication in Redis please check the
[replication page]().

title: Return information

text:
**RESP2:**

**Non-standard return value**, a bulk transfer of the data followed by `PING` and write requests from the master.

**RESP3:**

**Non-standard return value**, a bulk transfer of the data followed by `PING` and write requests from the master.


title: PTTL

summary: Returns the expiration time in milliseconds of a key.

title: Overview

text:
Like [`TTL`]() this command returns the remaining time to live of a key that has an
expire set, with the sole difference that [`TTL`]() returns the amount of remaining
time in seconds while `PTTL` returns it in milliseconds.

In Redis 2.6 or older the command returns `-1` if the key does not exist or if the key exist but has no associated expire.

Starting with Redis 2.8 the return value in case of error changed:

* The command returns `-2` if the key does not exist.
* The command returns `-1` if the key exists but has no associated expire.

title: Examples

text:
SET mykey "Hello"
EXPIRE mykey 1
PTTL mykey

title: Return information

text:
**RESP2:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): TTL in milliseconds.
* [Integer reply](../../develop/reference/protocol-spec#integers): `-1` if the key exists but has no associated expiration.
* [Integer reply](../../develop/reference/protocol-spec#integers): `-2` if the key does not exist.

**RESP3:**

One of the following:
* [Integer reply](../../develop/reference/protocol-spec#integers): TTL in milliseconds.
* [Integer reply](../../develop/reference/protocol-spec#integers): `-1` if the key exists but has no associated expiration.
* [Integer reply](../../develop/reference/protocol-spec#integers): `-2` if the key does not exist.


title: PUBLISH

summary: Posts a message to a channel.

title: Overview

text:
Posts a message to the given channel.

In a Redis Cluster clients can publish to every node. The cluster makes sure
that published messages are forwarded as needed, so clients can subscribe to any
channel by connecting to any one of the nodes.

title: Return information

text:
**RESP2:**

[Integer reply](../../develop/reference/protocol-spec#integers): the number of clients that the message was sent to. Note that in a Redis Cluster, only clients that are connected to the same node as the publishing client are included in the count.

**RESP3:**

[Integer reply](../../develop/reference/protocol-spec#integers): the number of clients that the message was sent to. Note that in a Redis Cluster, only clients that are connected to the same node as the publishing client are included in the count.


title: PUBSUB

summary: A container for Pub/Sub commands.

title: Content

text:
This is a container command for Pub/Sub introspection commands.

To see the list of available commands you can call [`PUBSUB HELP`]().


title: PUBSUB CHANNELS

summary: Returns the active channels.

title: Overview

text:
Lists the currently *active channels*.

An active channel is a Pub/Sub channel with one or more subscribers (excluding clients subscribed to patterns).

If no `pattern` is specified, all the channels are listed, otherwise if pattern is specified only channels matching the specified glob-style pattern are listed.

Cluster note: in a Redis Cluster clients can subscribe to every node, and can also publish to every other node. The cluster will make sure that published messages are forwarded as needed. That said, [`PUBSUB`]()'s replies in a cluster only report information from the node's Pub/Sub context, rather than the entire cluster.

title: Return information

text:
**RESP2:**

[Array reply](../../develop/reference/protocol-spec#arrays): a list of active channels, optionally matching the specified pattern.

**RESP3:**

[Array reply](../../develop/reference/protocol-spec#arrays): a list of active channels, optionally matching the specified pattern.


title: PUBSUB HELP

title: Overview

text: The `PUBSUB HELP` command returns a helpful text describing the different subcommands.

text:
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ❌ Standard
<nobr>❌ Active-Active</nobr> | ❌ Standard
<nobr>❌ Active-Active</nobr> |  |

title: Return information

text:
**RESP2:**

[Array reply](../../develop/reference/protocol-spec#arrays): a list of sub-commands and their descriptions.

**RESP3:**

[Array reply](../../develop/reference/protocol-spec#arrays): a list of sub-commands and their descriptions.


title: PUBSUB NUMPAT

summary: Returns a count of unique pattern subscriptions.

title: Overview

text:
Returns the number of unique patterns that are subscribed to by clients (that are performed using the [`PSUBSCRIBE`]() command).

Note that this isn't the count of clients subscribed to patterns, but the total number of unique patterns all the clients are subscribed to.

Cluster note: in a Redis Cluster clients can subscribe to every node, and can also publish to every other node. The cluster will make sure that published messages are forwarded as needed. That said, [`PUBSUB`]()'s replies in a cluster only report information from the node's Pub/Sub context, rather than the entire cluster.

text:
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ✅ Standard
<nobr>✅ Active-Active</nobr> | ✅ Standard
<nobr>✅ Active-Active</nobr> |  |

title: Return information

text:
**RESP2:**

[Integer reply](../../develop/reference/protocol-spec#integers): the number of patterns all the clients are subscribed to.

**RESP3:**

[Integer reply](../../develop/reference/protocol-spec#integers): the number of patterns all the clients are subscribed to.


title: PUBSUB NUMSUB

summary: Returns a count of subscribers to channels.

title: Overview

text:
Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified channels.

Note that it is valid to call this command without channels. In this case it will just return an empty list.

Cluster note: in a Redis Cluster clients can subscribe to every node, and can also publish to every other node. The cluster will make sure that published messages are forwarded as needed. That said, [`PUBSUB`]()'s replies in a cluster only report information from the node's Pub/Sub context, rather than the entire cluster.

title: Return information

text:
**RESP2:**

[Array reply](../../develop/reference/protocol-spec#arrays): the number of subscribers per channel, each even element (including the 0th) is channel name, each odd element is the number of subscribers

**RESP3:**

[Array reply](../../develop/reference/protocol-spec#arrays): the number of subscribers per channel, each even element (including the 0th) is channel name, each odd element is the number of subscribers


title: PUBSUB SHARDCHANNELS

summary: Returns the active shard channels.

title: Overview

text:
Lists the currently *active shard channels*.

An active shard channel is a Pub/Sub shard channel with one or more subscribers.

If no `pattern` is specified, all the channels are listed, otherwise if pattern is specified only channels matching the specified glob-style pattern are listed.

The information returned about the active shard channels are at the shard level and not at the cluster level.

title: Examples

text: [code example]

title: Return information

code:
> PUBSUB SHARDCHANNELS
1) "orders"
> PUBSUB SHARDCHANNELS o*
1) "orders"

section_id: examples


title: PUBSUB SHARDNUMSUB

summary: Returns the count of subscribers of shard channels.

title: Overview

text:
Returns the number of subscribers for the specified shard channels.

Note that it is valid to call this command without channels, in this case it will just return an empty list.

Cluster note: in a Redis Cluster, [`PUBSUB`]()'s replies in a cluster only report information from the node's Pub/Sub context, rather than the entire cluster.

title: Examples

text: [code example]

title: Return information

text:
**RESP2:**

[Array reply](../../develop/reference/protocol-spec#arrays): the number of subscribers per shard channel, each even element (including the 0th) is channel name, each odd element is the number of subscribers.

**RESP3:**

[Array reply](../../develop/reference/protocol-spec#arrays): the number of subscribers per shard channel, each even element (including the 0th) is channel name, each odd element is the number of subscribers.

code:
> PUBSUB SHARDNUMSUB orders
1) "orders"
2) (integer) 1


title: PUNSUBSCRIBE

summary: Stops listening to messages published to channels that match one or more patterns.

title: Overview

text:
Unsubscribes the client from the given patterns, or from all of them if none is
given.

When no patterns are specified, the client is unsubscribed from all the
previously subscribed patterns.
In this case, a message for every unsubscribed pattern will be sent to the
client.

title: Return information

text:
**RESP2:**

When successful, this command doesn't return anything. Instead, for each pattern, one message with the first element being the string `punsubscribe` is pushed as a confirmation that the command succeeded.

**RESP3:**

When successful, this command doesn't return anything. Instead, for each pattern, one message with the first element being the string `punsubscribe` is pushed as a confirmation that the command succeeded.


title: QUIT

summary: Closes the connection.

title: Overview

text:
Ask the server to close the connection.
The connection is closed as soon as all pending replies have been written to the
client.

**Note:** Clients should not use this command.
Instead, clients should simply close the connection when they're not used anymore.
Terminating a connection on the client side is preferable, as it eliminates `TIME_WAIT` lingering sockets on the server side.

text:
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ✅ Standard
<nobr>✅ Active-Active</nobr> | ✅ Standard
<nobr>✅ Active-Active</nobr> | Deprecated as of Redis v7.2.0. |

title: Return information

text:
**RESP2:**

[Simple string reply](../../develop/reference/protocol-spec#simple-strings): OK.

**RESP3:**

[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.


title: RANDOMKEY

summary: Returns a random key name from the database.

title: Overview

text: Return a random key from the currently selected database.

title: Return information

text:
**RESP2:**

One of the following:
* [Nil reply](../../develop/reference/protocol-spec#bulk-strings): when the database is empty.
* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): a random key in database.

**RESP3:**

One of the following:
* [Null reply](../../develop/reference/protocol-spec#nulls): when the database is empty.
* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): a random key in the database.


title: READONLY

summary: Enables read-only queries for a connection to a Redis Cluster replica node.

title: Overview

text:
Enables read queries for a connection to a Redis Cluster replica node.

Normally replica nodes will redirect clients to the authoritative master for
the hash slot involved in a given command, however clients can use replicas
in order to scale reads using the `READONLY` command.

`READONLY` tells a Redis Cluster replica node that the client is willing to
read possibly stale data and is not interested in running write queries.

When the connection is in readonly mode, the cluster will send a redirection
to the client only if the operation involves keys not served by the replica's
master node. This may happen because:

1. The client sent a command about hash slots never served by the master of this replica.
2. The cluster was reconfigured (for example resharded) and the replica is no longer able to serve commands for a given hash slot.

text:
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ❌ Standard
<nobr>❌ Active-Active</nobr> | ❌ Standard
<nobr>❌ Active-Active</nobr> |  |

title: Return information

text:
**RESP2:**

[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.

**RESP3:**

[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.


title: READWRITE

summary: Enables read-write queries for a connection to a Redis Cluster replica node.

title: Overview

text:
Disables read queries for a connection to a Redis Cluster replica node.

Read queries against a Redis Cluster replica node are disabled by default,
but you can use the [`READONLY`]() command to change this behavior on a per-
connection basis. The `READWRITE` command resets the readonly mode flag
of a connection back to readwrite.

title: Return information