Skip to content

Commit 83557c9

Browse files
authored
Clustering sendCommand docs
We noticed that `sendCommand()` takes different arguments for clusters vs clients, and I wanted to document the differences. I think I got it correct, but please review closely just to be sure. It might also be worth adding a note to [the readme](https://github.com/redis/node-redis/blob/2f106324507eec905b8fe7691ba11179acdeeca7/README.md#L136-L144) also, since this is a somewhat unexpected difference, what do you think? Relates to express-rate-limit/rate-limit-redis#207 & express-rate-limit/rate-limit-redis#208
1 parent 2f10632 commit 83557c9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/clustering.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ await cluster.close();
3838
| scripts | | Script definitions (see [Lua Scripts](./programmability.md#lua-scripts)) |
3939
| functions | | Function definitions (see [Functions](./programmability.md#functions)) |
4040

41+
## Usage
42+
43+
Most redis commands are the same as with individual clients.
44+
45+
### Unsupported Redis Commands
46+
47+
If you want to run commands and/or use arguments that Node Redis doesn't know about (yet!) use `.sendCommand()`.
48+
49+
When clustering, `sendCommand` takes 3 arguments to help with routing to the correct redis node:
50+
* `firstKey`: the key that is being operated on, or `undefined` to route to a random node.
51+
* `isReadOnly`: determines if the command needs to go to the master or may go to a replica.
52+
* `args`: the command and all arguments (including the key), as an array of strings.
53+
54+
```javascript
55+
await cluster.sendCommand("key", false, ["SET", "key", "value", "NX"]); // 'OK'
56+
57+
await cluster.sendCommand("key", true, ["HGETALL", "key"]); // ['key1', 'field1', 'key2', 'field2']
58+
```
59+
4160
## Auth with password and username
4261

4362
Specifying the password in the URL or a root node will only affect the connection to that specific node. In case you want to set the password for all the connections being created from a cluster instance, use the `defaults` option.
@@ -114,3 +133,4 @@ Admin commands such as `MEMORY STATS`, `FLUSHALL`, etc. are not attached to the
114133
### "Forwarded Commands"
115134

116135
Certain commands (e.g. `PUBLISH`) are forwarded to other cluster nodes by the Redis server. The client sends these commands to a random node in order to spread the load across the cluster.
136+

0 commit comments

Comments
 (0)