You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also specify connection options as a [`redis://` URL](http://www.iana.org/assignments/uri-schemes/prov/redis) or [`rediss://` URL](https://www.iana.org/assignments/uri-schemes/prov/rediss) when using [TLS encryption](#tls-options):
Besides `defineCommand()`, you can also define custom commands with the `scripts` constructor option:
519
+
520
+
```javascript
521
+
constredis=newRedis({
522
+
scripts: {
523
+
myecho: {
524
+
numberOfKeys:2,
525
+
lua:"return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
526
+
},
527
+
},
528
+
});
529
+
```
530
+
531
+
### TypeScript Usages
532
+
533
+
You can refer to [the example](examples/typescript/scripts.ts) for how to declare your custom commands.
534
+
515
535
## Transparent Key Prefixing
516
536
517
537
This feature allows you to specify a string that will automatically be prepended
@@ -769,7 +789,7 @@ const redis = new Redis({
769
789
770
790
Set maxRetriesPerRequest to `null` to disable this behavior, and every command will wait forever until the connection is alive again (which is the default behavior before ioredis v4).
771
791
772
-
### Reconnect on error
792
+
### Reconnect on Error
773
793
774
794
Besides auto-reconnect when the connection is closed, ioredis supports reconnecting on certain Redis errors using the `reconnectOnError` option. Here's an example that will reconnect when receiving `READONLY` error:
- `slotsRefreshTimeout`: Milliseconds before a timeout occurs while refreshing slots from the cluster (default `1000`).
1021
1041
- `slotsRefreshInterval`: Milliseconds between every automatic slots refresh (default `5000`).
1022
1042
1023
-
### Read-write splitting
1043
+
### Read-Write Splitting
1024
1044
1025
1045
A typical redis cluster contains three or more masters and several slaves for each master. It's possible to scale out redis cluster by sending read queries to slaves and write queries to masters by setting the `scaleReads` option.
**NB** In the code snippet above, the `res` may not be equal to "bar" because of the lag of replication between the master and slaves.
1051
1071
1052
-
### Running commands to multiple nodes
1072
+
### Running Commands to Multiple Nodes
1053
1073
1054
1074
Every command will be sent to exactly one node. For commands containing keys, (e.g. `GET`, `SET` and `HGETALL`), ioredis sends them to the node that serving the keys, and for other commands not containing keys, (e.g. `INFO`, `KEYS` and `FLUSHDB`), ioredis sends them to a random node.
1055
1075
@@ -1099,7 +1119,7 @@ const cluster = new Redis.Cluster(
1099
1119
1100
1120
This option is also useful when the cluster is running inside a Docker container.
1101
1121
1102
-
### Transaction and pipeline in Cluster mode
1122
+
### Transaction and Pipeline in Cluster Mode
1103
1123
1104
1124
Almost all features that are supported by `Redis` are also supported by `Redis.Cluster`, e.g. custom commands, transaction and pipeline.
1105
1125
However there are some differences when using transaction and pipeline in Cluster mode:
@@ -1178,7 +1198,7 @@ const cluster = new Redis.Cluster(
1178
1198
);
1179
1199
```
1180
1200
1181
-
### Special note: AWS ElastiCache Clusters with TLS
1201
+
### Special Note: Aws Elasticache Clusters with TLS
1182
1202
1183
1203
AWS ElastiCache for Redis (Clustered Mode) supports TLS encryption. If you use
1184
1204
this, you may encounter errors with invalid certificates. To resolve this
@@ -1223,7 +1243,7 @@ A pipeline will thus contain commands using different slots but that ultimately
1223
1243
1224
1244
Note that the same slot limitation within a single command still holds, as it is a Redis limitation.
1225
1245
1226
-
### Example of automatic pipeline enqueuing
1246
+
### Example of Automatic Pipeline Enqueuing
1227
1247
1228
1248
This sample code uses ioredis with automatic pipeline enabled.
0 commit comments