CLIENT UNBLOCK client-id [TIMEOUT|ERROR]

    Time complexity: O(log N) where N is the number of client connections

    This command can unblock, from a different connection, a client blocked in a blocking operation, such as for instance or XREAD or .

    Note: of course as usually it is not guaranteed that the error text remains the same, however the error code will remain .

    This command is useful especially when we are monitoring many keys with a limited number of connections. For instance we may want to monitor multiple streams with XREAD without using more than N connections. However at some point the consumer process is informed that there is one more stream key to monitor. In order to avoid using more connections, the best behavior would be to stop the blocking command from one of the connections in the pool, add the new key, and issue the blocking command again.

    This example shows the application in the context of Redis streams, however the pattern is a general one and can be applied to other cases.

    1. Connection A (blocking connection):
    2. > CLIENT ID
    3. 2934
    4. > BRPOP key1 key2 key3 0
    5. (client is blocked)
    6. ... Now we want to add a new key ...
    7. Connection B (control connection):
    8. > CLIENT UNBLOCK 2934
    9. 1
    10. ... BRPOP reply with timeout ...
    11. NULL
    12. > BRPOP key1 key2 key3 key4 0
    13. (client is blocked again)

    , specifically:

    • if the client was unblocked successfully.
    • 0 if the client wasn't unblocked.