Skip to content

Commit fb8630f

Browse files
committed
docs: clarify suffix use cases
Related to #1586
1 parent 91ed2d8 commit fb8630f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

README.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,27 @@ listenForMessage();
312312

313313
## Handle Binary Data
314314

315-
Arguments can be buffers:
315+
Binary data support is out of the box. Pass buffers to send binary data:
316316

317317
```javascript
318-
redis.set("foo", Buffer.from("bar"));
318+
redis.set("foo", Buffer.from([0x62, 0x75, 0x66]));
319319
```
320320

321-
And every command has a method that returns a Buffer (by adding a suffix of "Buffer" to the command name).
322-
To get a buffer instead of a utf8 string:
321+
Every command that returns a [bulk string](https://redis.io/docs/reference/protocol-spec/#resp-bulk-strings)
322+
has a variant command with a `Buffer` suffix. The variant command returns a buffer instead of a UTF-8 string:
323323

324324
```javascript
325-
redis.getBuffer("foo", (err, result) => {
326-
// result is a buffer.
327-
});
325+
const result = await redis.getBuffer("foo");
326+
// result is `<Buffer 62 75 66>`
327+
```
328+
329+
It's worth noticing that you don't need the `Buffer` suffix variant in order to **send** binary data. That means
330+
in most case you should just use `redis.set()` instead of `redis.setBuffer()` unless you want to get the old value
331+
with the `GET` parameter:
332+
333+
```javascript
334+
const result = await redis.setBuffer("foo", "new value", "GET");
335+
// result is `<Buffer 62 75 66>` as `GET` indicates returning the old value.
328336
```
329337

330338
## Pipelining

0 commit comments

Comments
 (0)