File tree 1 file changed +15
-7
lines changed
1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -312,19 +312,27 @@ listenForMessage();
312
312
313
313
## Handle Binary Data
314
314
315
- Arguments can be buffers:
315
+ Binary data support is out of the box. Pass buffers to send binary data :
316
316
317
317
``` javascript
318
- redis .set (" foo" , Buffer .from (" bar " ));
318
+ redis .set (" foo" , Buffer .from ([ 0x62 , 0x75 , 0x66 ] ));
319
319
```
320
320
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:
323
323
324
324
``` 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.
328
336
```
329
337
330
338
## Pipelining
You can’t perform that action at this time.
0 commit comments