1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

fix multi "generic" type, some docs

This commit is contained in:
Leibale
2023-11-20 13:15:40 -05:00
parent 3ca33b8b80
commit 520441704b
4 changed files with 66 additions and 13 deletions

View File

@@ -40,6 +40,7 @@ await cluster.close();
## 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.
```javascript
createCluster({
rootNodes: [{

29
docs/transactions.md Normal file
View File

@@ -0,0 +1,29 @@
# [Transactions](https://redis.io/docs/interact/transactions/) ([`MULTI`](https://redis.io/commands/multi/)/[`EXEC`](https://redis.io/commands/exec/))
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:
```javascript
const [setReply, getReply] = await client.multi()
.set('key', 'value')
.get('another-key')
.exec();
```
## `exec<'typed'>()`/`execTyped()`
A transaction invoked with `.exec<'typed'>`/`execTyped()` will return types appropriate to the commands in the transaction:
```javascript
const multi = client.multi().ping();
await multi.exec(); // Array<ReplyUnion>
await multi.exec<'typed'>(); // [string]
await multi.execTyped(); // [string]
```
> :warning: this only works when all the commands are invoked in a single "call chain"
## [`WATCH`](https://redis.io/commands/watch/)
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.
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).