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):
127
132
128
133
```javascript
134
+
const { Valkey } =require("iovalkey");
129
135
// Connect to 127.0.0.1:6380, db 4, using password "authpassword":
Valkey v5 introduces a new data type called streams. It doubles as a communication channel for building streaming architectures and as a log-like data structure for persisting data. With iovalkey, the usage can be pretty straightforward. Say we have a producer publishes messages to a stream with `valkey.xadd("mystream", "*", "randomValue", Math.random())` (You may find the [official documentation of Streams](https://valkey.io/topics/streams-intro/) as a starter to understand the parameters used), to consume the messages, we'll have a consumer with the following code:
225
231
226
232
```javascript
227
-
constValkey=require("iovalkey");
233
+
const { Valkey } =require("iovalkey");
234
+
228
235
constvalkey=newValkey();
229
236
230
237
constprocessMessage= (message) => {
@@ -449,6 +456,8 @@ care of script caching and to detect when to use `EVAL` and when to use `EVALSHA
449
456
iovalkey exposes a `defineCommand` method to make scripting much easier to use:
Besides `defineCommand()`, you can also define custom commands with the `scripts` constructor option:
496
505
497
506
```javascript
507
+
const { Valkey } =require("iovalkey");
508
+
498
509
constvalkey=newValkey({
499
510
scripts: {
500
511
myecho: {
@@ -519,6 +530,8 @@ namespaces.
519
530
and this feature also won't apply to the replies of commands even if they are key names ([#325](https://github.com/mcollina/iovalkey/issues/325)).
520
531
521
532
```javascript
533
+
const { Valkey } =require("iovalkey");
534
+
522
535
constfooValkey=newValkey({ keyPrefix:"foo:" });
523
536
fooValkey.set("bar", "baz"); // Actually sends SET foo:bar baz
524
537
@@ -549,15 +562,17 @@ iovalkey has a flexible system for transforming arguments and replies. There are
549
562
of transformers, argument transformer and reply transformer:
550
563
551
564
```javascript
552
-
constValkey=require("iovalkey");
565
+
const { Command } =require("iovalkey");
566
+
567
+
constvalkey=newValkey();
553
568
554
569
// Here's the built-in argument transformer converting
555
570
// hmset('key', { k1: 'v1', k2: 'v2' })
556
571
// or
557
572
// hmset('key', new Map([['k1', 'v1'], ['k2', 'v2']]))
Another useful example of a reply transformer is one that changes `hgetall` to return array of arrays instead of objects which avoids an unwanted conversation of hash keys to strings when dealing with binary hash keys:
@@ -935,9 +958,9 @@ Valkey Cluster provides a way to run a Valkey installation where data is automat
935
958
You can connect to a Valkey Cluster like this:
936
959
937
960
```javascript
938
-
constValkey=require("iovalkey");
961
+
const{ Cluster }=require("iovalkey");
939
962
940
-
constcluster=newValkey.Cluster([
963
+
constcluster=newCluster([
941
964
{
942
965
port:6380,
943
966
host:"127.0.0.1",
@@ -1015,7 +1038,8 @@ A typical valkey cluster contains three or more masters and several slaves for e
1015
1038
For example:
1016
1039
1017
1040
```javascript
1018
-
const cluster = new Valkey.Cluster(
1041
+
const { Cluster } =require("iovalkey");
1042
+
constcluster=newCluster(
1019
1043
[
1020
1044
/* nodes */
1021
1045
],
@@ -1062,7 +1086,9 @@ Sometimes the cluster is hosted within a internal network that can only be acces
1062
1086
You can specify nat mapping rules via `natMap` option:
1063
1087
1064
1088
```javascript
1065
-
constcluster=newValkey.Cluster(
1089
+
const { Cluster } =require("iovalkey");
1090
+
1091
+
constcluster=newCluster(
1066
1092
[
1067
1093
{
1068
1094
host:"203.0.113.73",
@@ -1081,7 +1107,9 @@ const cluster = new Valkey.Cluster(
1081
1107
1082
1108
Or you can specify this parameter through function:
1083
1109
```javascript
1084
-
constcluster=newRedis.Cluster(
1110
+
const { Cluster } =require("iovalkey");
1111
+
1112
+
constcluster=newCluster(
1085
1113
[
1086
1114
{
1087
1115
host:"203.0.113.73",
@@ -1134,11 +1162,13 @@ When any commands in a pipeline receives a `MOVED` or `ASK` error, iovalkey will
1134
1162
Pub/Sub in cluster mode works exactly as the same as in standalone mode. Internally, when a node of the cluster receives a message, it will broadcast the message to the other nodes. iovalkey makes sure that each message will only be received once by strictly subscribing one node at the same time.
0 commit comments