Skip to content

Commit 86bbe94

Browse files
committed
Fix typo and improve Sentinel docs
1 parent 5295926 commit 86bbe94

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

docs/sentinel.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const sentinel = await createSentinel({
1414
port: 1234
1515
}]
1616
})
17-
.on('error', err => console.error('Redis Sentinel Error', err));
17+
.on('error', err => console.error('Redis Sentinel Error', err))
1818
.connect();
1919

2020
await sentinel.set('key', 'value');
@@ -26,16 +26,19 @@ In the above example, we configure the sentinel object to fetch the configuratio
2626

2727
## `createSentinel` configuration
2828

29-
| Property | Default | Description |
30-
|-----------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
31-
| name | | The sentinel identifier for a particular database cluster |
32-
| sentinelRootNodes | | An array of root nodes that are part of the sentinel cluster, which will be used to get the topology. Each element in the array is a client configuration object. There is no need to specify every node in the cluster: 3 should be enough to reliably connect and obtain the sentinel configuration from the server |
33-
| maxCommandRediscovers | `16` | The maximum number of times a command will retry due to topology changes. |
34-
| nodeClientOptions | | The configuration values for every node in the cluster. Use this for example when specifying an ACL user to connect with |
35-
| sentinelClientOptions | | The configuration values for every sentinel in the cluster. Use this for example when specifying an ACL user to connect with |
36-
| masterPoolSize | `1` | The number of clients connected to the master node |
37-
| replicaPoolSize | `0` | The number of clients connected to each replica node. When greater than 0, the client will distribute the load by executing read-only commands (such as `GET`, `GEOSEARCH`, etc.) across all the cluster nodes. |
38-
| reserveClient | `false` | When `true`, one client will be reserved for the sentinel object. When `false`, the sentinel object will wait for the first available client from the pool. |
29+
| Property | Default | Description |
30+
|----------------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
31+
| name | | The sentinel identifier for a particular database cluster |
32+
| sentinelRootNodes | | An array of root nodes that are part of the sentinel cluster, which will be used to get the topology. Each element in the array is a client configuration object. There is no need to specify every node in the cluster: 3 should be enough to reliably connect and obtain the sentinel configuration from the server |
33+
| maxCommandRediscovers | `16` | The maximum number of times a command will retry due to topology changes. |
34+
| nodeClientOptions | | The configuration values for every node in the cluster. Use this for example when specifying an ACL user to connect with |
35+
| sentinelClientOptions | | The configuration values for every sentinel in the cluster. Use this for example when specifying an ACL user to connect with |
36+
| masterPoolSize | `1` | The number of clients connected to the master node |
37+
| replicaPoolSize | `0` | The number of clients connected to each replica node. When greater than 0, the client will distribute the load by executing read-only commands (such as `GET`, `GEOSEARCH`, etc.) across all the cluster nodes. |
38+
| scanInterval | `10000` | Interval in milliseconds to periodically scan for changes in the sentinel topology. The client will query the sentinel for changes at this interval. |
39+
| passthroughClientErrorEvents | `false` | When `true`, error events from client instances inside the sentinel will be propagated to the sentinel instance. This allows handling all client errors through a single error handler on the sentinel instance. |
40+
| reserveClient | `false` | When `true`, one client will be reserved for the sentinel object. When `false`, the sentinel object will wait for the first available client from the pool. |
41+
3942
## PubSub
4043

4144
It supports PubSub via the normal mechanisms, including migrating the listeners if the node they are connected to goes down.
@@ -60,7 +63,7 @@ createSentinel({
6063
});
6164
```
6265

63-
In addition, it also provides the ability have a pool of clients connected to the replica nodes, and to direct all read-only commands to them:
66+
In addition, it also provides the ability have a pool of clients connected to the replica nodes, and to direct all read-only commands to them:
6467

6568
```javascript
6669
createSentinel({
@@ -85,9 +88,9 @@ const result = await sentinel.use(async client => {
8588
});
8689
```
8790

88-
`.getMasterClientLease()`
91+
`.acquire()`
8992
```javascript
90-
const clientLease = await sentinel.getMasterClientLease();
93+
const clientLease = await sentinel.acquire();
9194

9295
try {
9396
await clientLease.watch('key');

packages/client/lib/sentinel/index.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ async function steadyState(frame: SentinelFramework) {
488488
sentinel.on("error", () => { });
489489
await sentinel.connect();
490490

491-
const clientLease = await sentinel.aquire();
491+
const clientLease = await sentinel.acquire();
492492
clientLease.set('x', 456);
493493

494494
let matched = false;
@@ -554,7 +554,7 @@ async function steadyState(frame: SentinelFramework) {
554554
sentinel = frame.getSentinelClient({ masterPoolSize: 2 });
555555
await sentinel.connect();
556556

557-
const leasedClient = await sentinel.aquire();
557+
const leasedClient = await sentinel.acquire();
558558
await leasedClient.set('x', 1);
559559
await leasedClient.watch('x');
560560
assert.deepEqual(await leasedClient.multi().get('x').exec(), ['1'])
@@ -630,8 +630,8 @@ async function steadyState(frame: SentinelFramework) {
630630

631631
tracer.push("connected");
632632

633-
const client = await sentinel.aquire();
634-
tracer.push("aquired lease");
633+
const client = await sentinel.acquire();
634+
tracer.push("acquired lease");
635635

636636
await client.set("x", 1);
637637
await client.watch("x");
@@ -678,7 +678,7 @@ async function steadyState(frame: SentinelFramework) {
678678
await sentinel.connect();
679679
tracer.push("connected");
680680

681-
const client = await sentinel.aquire();
681+
const client = await sentinel.acquire();
682682
tracer.push("got leased client");
683683
await client.set("x", 1);
684684
await client.watch("x");

packages/client/lib/sentinel/index.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,28 @@ export default class RedisSentinel<
508508

509509
pUnsubscribe = this.PUNSUBSCRIBE;
510510

511-
async aquire(): Promise<RedisSentinelClientType<M, F, S, RESP, TYPE_MAPPING>> {
511+
/**
512+
* Acquires a master client lease for exclusive operations
513+
*
514+
* Used when multiple commands need to run on an exclusive client (for example, using `WATCH/MULTI/EXEC`).
515+
* The returned client must be released after use with the `release()` method.
516+
*
517+
* @returns A promise that resolves to a Redis client connected to the master node
518+
* @example
519+
* ```javascript
520+
* const clientLease = await sentinel.acquire();
521+
*
522+
* try {
523+
* await clientLease.watch('key');
524+
* const resp = await clientLease.multi()
525+
* .get('key')
526+
* .exec();
527+
* } finally {
528+
* clientLease.release();
529+
* }
530+
* ```
531+
*/
532+
async acquire(): Promise<RedisSentinelClientType<M, F, S, RESP, TYPE_MAPPING>> {
512533
const clientInfo = await this._self.#internal.getClientLease();
513534
return RedisSentinelClient.create(this._self.#options, this._self.#internal, clientInfo, this._self.#commandOptions);
514535
}

packages/client/lib/sentinel/types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ export interface RedisSentinelOptions<
4949
*/
5050
replicaPoolSize?: number;
5151
/**
52-
* TODO
52+
* Interval in milliseconds to periodically scan for changes in the sentinel topology.
53+
* The client will query the sentinel for changes at this interval.
54+
*
55+
* Default: 10000 (10 seconds)
5356
*/
5457
scanInterval?: number;
5558
/**
56-
* TODO
59+
* When `true`, error events from client instances inside the sentinel will be propagated to the sentinel instance.
60+
* This allows handling all client errors through a single error handler on the sentinel instance.
61+
*
62+
* Default: false
5763
*/
5864
passthroughClientErrorEvents?: boolean;
5965
/**

0 commit comments

Comments
 (0)