You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-12-09 21:21:11 +03:00
docs: Clustering sendCommand docs (#3053)
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.
This commit is contained in:
@@ -38,6 +38,25 @@ await cluster.close();
|
|||||||
| scripts | | Script definitions (see [Lua Scripts](./programmability.md#lua-scripts)) |
|
| scripts | | Script definitions (see [Lua Scripts](./programmability.md#lua-scripts)) |
|
||||||
| functions | | Function definitions (see [Functions](./programmability.md#functions)) |
|
| functions | | Function definitions (see [Functions](./programmability.md#functions)) |
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Most redis commands are the same as with individual clients.
|
||||||
|
|
||||||
|
### Unsupported Redis Commands
|
||||||
|
|
||||||
|
If you want to run commands and/or use arguments that Node Redis doesn't know about (yet!) use `.sendCommand()`.
|
||||||
|
|
||||||
|
When clustering, `sendCommand` takes 3 arguments to help with routing to the correct redis node:
|
||||||
|
* `firstKey`: the key that is being operated on, or `undefined` to route to a random node.
|
||||||
|
* `isReadOnly`: determines if the command needs to go to the master or may go to a replica.
|
||||||
|
* `args`: the command and all arguments (including the key), as an array of strings.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await cluster.sendCommand("key", false, ["SET", "key", "value", "NX"]); // 'OK'
|
||||||
|
|
||||||
|
await cluster.sendCommand("key", true, ["HGETALL", "key"]); // ['key1', 'field1', 'key2', 'field2']
|
||||||
|
```
|
||||||
|
|
||||||
## Auth with password and username
|
## Auth with password and username
|
||||||
|
|
||||||
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.
|
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
|
|||||||
### "Forwarded Commands"
|
### "Forwarded Commands"
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user