Difficulty: Advanced
What does CLIENT REPLY OFF do, how is it different from SKIP, and when is it actually a good idea?
CLIENT REPLY OFF tells Redis to stop sending any replies to the current connection; commands still execute, but the client gets no response, not even errors. CLIENT REPLY SKIP suppresses the reply for only the next command, and CLIENT REPLY ON restores normal behaviour. It exists for fire-and-forget workloads where the client will never look at the results and wants to save the server and network the work of sending them.
| Mode | Effect | Reply to the CLIENT REPLY command itself |
|---|---|---|
ON | Normal: one reply per command | OK |
OFF | No replies until ON | None |
SKIP | Next command's reply is dropped | None |
The command has been available since Redis 3.2.
Almost every client library matches replies to requests in order: the third reply belongs to the third command. If replies stop arriving, the library waits forever or pairs the wrong reply with the wrong request. So CLIENT REPLY OFF is mainly useful when you control the raw RESP stream yourself, for example a custom loader or log shipper writing directly to a socket.
In most real systems, pipelining gives most of the same benefit safely: send many commands without waiting, read all replies at the end. You keep error reporting and libraries support it out of the box.
WRONGTYPE error or a NOPERM from ACLs is silently discarded. You will not know a write failed.+OK are tiny. The win is mostly avoiding reply processing and buffering.SET or HSET commands, then turn replies back on and send a final PING to know everything before it has been processed.SKIP for a single noisy command in the middle of an otherwise normal raw session.For bulk imports, the documented approach is redis-cli --pipe, which streams raw protocol and reports the error and reply counts at the end, so check that before reaching for CLIENT REPLY OFF.
import socket
s = socket.create_connection(("localhost", 6379))
cmds = [b"CLIENT REPLY OFF"]
cmds += [f"INCR hits:page:{i % 10}".encode() for i in range(10_000)]
cmds += [b"CLIENT REPLY ON", b"PING"] # turn replies back on, then a marker
# Inline commands, one per line
s.sendall(b"\r\n".join(cmds) + b"\r\n")
# Only the replies to CLIENT REPLY ON and PING come back
print(s.recv(64))
s.close()
The 10,000 INCR replies are never sent. Receiving PONG proves the server processed everything before it, but any error from an INCR is lost.
import Redis from 'ioredis';
const redis = new Redis();
const pipe = redis.pipeline();
for (let i = 0; i < 10000; i++) pipe.incr(`hits:page:${i % 10}`);
const results = await pipe.exec(); // [[err, value], ...]
const failed = results.filter(([err]) => err).length;
console.log({ failed });
Pipelining also avoids a round trip per command but keeps per-command errors, which is why it is preferred in application code.
CLIENT REPLY, Fire and forget, Pipelining, Mass insertion, RESP protocol