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
Copy file name to clipboardExpand all lines: docs/clustering.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,6 +40,7 @@ await cluster.close();
40
40
## Auth with password and username
41
41
42
42
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.
Start a [transaction](https://redis.io/docs/interact/transactions/) by calling `.multi()`, then chaining your commands. When you're done, call `.exec()` and you'll get an array back with your results:
4
+
5
+
```javascript
6
+
const [setReply, getReply] =awaitclient.multi()
7
+
.set('key', 'value')
8
+
.get('another-key')
9
+
.exec();
10
+
```
11
+
12
+
## `exec<'typed'>()`/`execTyped()`
13
+
14
+
A transaction invoked with `.exec<'typed'>`/`execTyped()` will return types appropriate to the commands in the transaction:
15
+
16
+
```javascript
17
+
constmulti=client.multi().ping();
18
+
awaitmulti.exec(); // Array<ReplyUnion>
19
+
awaitmulti.exec<'typed'>(); // [string]
20
+
awaitmulti.execTyped(); // [string]
21
+
```
22
+
23
+
> :warning: this only works when all the commands are invoked in a single "call chain"
24
+
25
+
## [`WATCH`](https://redis.io/commands/watch/)
26
+
27
+
You can also [watch](https://redis.io/docs/interact/transactions/#optimistic-locking-using-check-and-set) keys by calling `.watch()`. Your transaction will abort if any of the watched keys change.
28
+
29
+
The `WATCH` state is stored on the connection (by the server). In case you need to run multiple `WATCH` & `MULTI` in parallel you'll need to use a [pool](./pool.md).
Copy file name to clipboardExpand all lines: packages/redis/README.md
+34-10Lines changed: 34 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,9 @@ createClient({
55
55
56
56
You can also use discrete parameters, UNIX sockets, and even TLS to connect. Details can be found in the [client configuration guide](../../docs/client-configuration.md).
57
57
58
-
To check if the the client is connected and ready to send commands, use `client.isReady` which returns a boolean. `client.isOpen` is also available. This returns `true` when the client's underlying socket is open, and `false` when it isn't (for example when the client is still connecting or reconnecting after a network error).
58
+
To client exposes 2 `boolean`s that track the client state:
59
+
1.`isOpen` - the client is either connecting or connected.
60
+
2.`isReady` - the client is connected and ready to send
There are two functions that disconnect a client from the Redis server. In most scenarios you should use `.close()` to ensure that pending commands are sent to Redis before closing a connection.
108
-
109
-
> :warning: The `.quit()` and `.disconnect()` methods have been deprecated in v5. For more details, refer to the [v4-to-v5 guide](../../docs/v4-to-v5.md#quit-vs-disconnect).
110
-
111
108
#### `.close()`
112
109
110
+
Gracefully close a client's connection to Redis.
111
+
Wait for commands in process, but reject any new commands.
112
+
113
113
```javascript
114
114
const [ping, get] =awaitPromise.all([
115
115
client.ping(),
@@ -124,11 +124,34 @@ try {
124
124
}
125
125
```
126
126
127
-
> :warning:`.close` is just like `.quit()` which was depreacted in Redis 7.2. See the [relevant section in the migration guide](../../docs/v4-to-v5.md#Quit-VS-Disconnect) for more information.
127
+
> `.close()` is just like `.quit()` which was depreacted v5. See the [relevant section in the migration guide](../../docs/v4-to-v5.md#Quit-VS-Disconnect) for more information.
128
128
129
129
#### `.destroy()`
130
130
131
-
Forcibly close a client's connection to Redis immediately. Calling `destroy` will not send further pending commands to the Redis server, or wait for or parse outstanding responses.
131
+
Forcibly close a client's connection to Redis.
132
+
133
+
```javascript
134
+
try {
135
+
constpromise=Promise.all([
136
+
client.ping(),
137
+
client.get('key')
138
+
]);
139
+
140
+
client.destroy();
141
+
142
+
await promise;
143
+
} catch (err) {
144
+
// DisconnectsClientError
145
+
}
146
+
147
+
try {
148
+
awaitclient.get('key');
149
+
} catch (err) {
150
+
// ClientClosedError
151
+
}
152
+
```
153
+
154
+
> `.destroy()` is just like `.disconnect()` which was depreated in v5. See the [relevant section in the migration guide](../../docs/v4-to-v5.md#Quit-VS-Disconnect) for more information.
132
155
133
156
### Auto-Pipelining
134
157
@@ -167,7 +190,7 @@ The Node Redis client class is an Nodejs EventEmitter and it emits an event each
0 commit comments