CLIENT UNBLOCK
CLIENT UNBLOCK client-id [TIMEOUT | ERROR]
- Available since:
- Redis Open Source 5.0.0
- Time complexity:
- O(log N) where N is the number of client connections
- ACL categories:
-
@admin,@slow,@dangerous,@connection, - Compatibility:
- Redis Software and Redis Cloud compatibility
Use this command from one connection to unblock a client that is blocked by a blocking operation, such as BRPOP, XREAD, or WAIT.
By default, Redis unblocks the client as if the blocked command timed out. You can pass an optional argument to choose the unblocking behavior: TIMEOUT, the default, or ERROR. If you specify ERROR, Redis unblocks the client and returns an error that indicates the client was force-unblocked.Specifically the client will receive the following error:
-UNBLOCKED client unblocked via CLIENT UNBLOCK
The error text may change over time, but the error code will remain -UNBLOCKED.
Required arguments
client-id
The ID of the client to unblock.
Optional arguments
TIMEOUT | ERROR
How to unblock the client: as if its timeout expired (TIMEOUT, the default), or by returning an error (ERROR).
Details
Use this command when you need to monitor many keys with a limited number of connections. For example, you might monitor multiple streams with XREAD without using more than N connections. If your consumer process needs to monitor another stream key, you can avoid opening another connection: unblock one of the connections in the pool, add the new key, and issue the blocking command again.
To use this pattern, create an additional control connection that sends CLIENT UNBLOCK when needed. Before you run a blocking operation on each monitored connection, run CLIENT ID to get that connection’s ID. When you need to add or remove a key, use the control connection to send CLIENT UNBLOCK for the connection that is running the blocking command. The blocking command returns, and you can then reissue it with the updated set of keys.
The following example uses Redis Streams, but you can apply the same pattern to other blocking operations.
Connection A (blocking connection):
> CLIENT ID
2934
> BRPOP key1 key2 key3 0
(client is blocked)
... Now we want to add a new key ...
Connection B (control connection):
> CLIENT UNBLOCK 2934
1
Connection A (blocking connection):
... BRPOP reply with timeout ...
NULL
> BRPOP key1 key2 key3 key4 0
(client is blocked again)
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |
Return information
One of the following:
- Integer reply:
1if the client was unblocked successfully. - Integer reply:
0if the client wasn't unblocked.