@types/k6 0.47.3 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,26 +2,52 @@
2
2
  * This module provides a redis client allowing users to interact with redis,
3
3
  * directly from their k6 scripts.
4
4
  *
5
- * https://k6.io/docs/javascript-api/k6-experimental/redis/
5
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/
6
6
  */
7
7
 
8
8
  /**
9
- * `Client` is a Redis client to interact with a Redis server or cluster.
9
+ * `Client` is a Redis client for interacting with a Redis server or cluster.
10
10
  *
11
- * It exposes a promise-based API, allowing users to interact with Redis in an asynchronous manner.
11
+ * This client provides a promise-based API, enabling asynchronous operations with the Redis server.
12
+ * It supports a wide range of configurations, including single-node connections, cluster mode, and connections through Redis Sentinel.
12
13
  *
13
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client
14
+ * The client can be configured either by passing a `RedisClientOptions` object for fine-grained configuration,
15
+ * or by using a `RedisConnectionURL` string for simpler setups.
16
+ *
17
+ * For more information on the k6 Redis module, visit:
18
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client
14
19
  */
15
20
  export class Client {
16
21
  protected __brand: never;
17
22
 
18
23
  /**
19
- * Instantiate a new Redis client.
24
+ * Creates a new instance of the Redis client.
25
+ *
26
+ * The client can be configured in two ways:
27
+ * 1. By providing an object of `RedisClientOptions`, allowing detailed configuration including
28
+ * authentication, connection settings, client behaviors, and cluster or sentinel setups.
29
+ * 2. By providing a `RedisConnectionURL` string, suitable for straightforward configurations.
30
+ * The URL should follow the format: redis[s]://[[username][:password]@][host][:port][/db-number]
31
+ *
32
+ * Example usage:
33
+ * ```
34
+ * // Using RedisClientOptions
35
+ * const client = new Client({
36
+ * socket: {
37
+ * host: 'localhost',
38
+ * port: 6379
39
+ * },
40
+ * password: 'yourpassword'
41
+ * });
20
42
  *
21
- * @param options - Options.
22
- * @returns instantiated Client
43
+ * // Using RedisConnectionURL
44
+ * const client = new Client('redis://user:password@localhost:6379/0');
45
+ * ```
46
+ *
47
+ * @param options - The configuration options for the client, either as a `RedisClientOptions` object or a `RedisConnectionURL` string.
48
+ * @returns The instantiated Redis client.
23
49
  */
24
- constructor(options: Options);
50
+ constructor(options: RedisClientOptions | RedisConnectionURL);
25
51
 
26
52
  /**
27
53
  * Sets the value of a key, with a time to live (ttl) value equal to
@@ -29,7 +55,7 @@ export class Client {
29
55
  *
30
56
  * If the key already exists, it is overwritten.
31
57
  *
32
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-set
58
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-set
33
59
  *
34
60
  * @param key - key to set
35
61
  * @param value - value to set
@@ -41,7 +67,7 @@ export class Client {
41
67
  /**
42
68
  * Gets the value of a key.
43
69
  *
44
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-get
70
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-get
45
71
  *
46
72
  * @param key - key to get
47
73
  * @returns a promise that resolves to the value of the key.
@@ -52,7 +78,7 @@ export class Client {
52
78
  * Atomically sets the value of a key and returns the value
53
79
  * previously stored at that key.
54
80
  *
55
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-getset
81
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-getset
56
82
  *
57
83
  * @param key - key to get and set
58
84
  * @param value - value to set
@@ -65,7 +91,7 @@ export class Client {
65
91
  *
66
92
  * A key is ignored if it does not exist.
67
93
  *
68
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-del
94
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-del
69
95
  *
70
96
  * @param keys - keys to delete
71
97
  * @returns a promise that resolves to the number of keys that were removed.
@@ -75,7 +101,7 @@ export class Client {
75
101
  /**
76
102
  * Get the value of a key and delete it.
77
103
  *
78
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-getdel
104
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-getdel
79
105
  *
80
106
  * @param key - the key to get and delete
81
107
  * @returns a promise that resolves to the value of the key that was deleted.
@@ -85,7 +111,7 @@ export class Client {
85
111
  /**
86
112
  * Returns the number of the provided keys arguments that exist.
87
113
  *
88
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-exists
114
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-exists
89
115
  *
90
116
  * @param keys - the keys to check the existence of
91
117
  * @returns a promise that resolves to the number of keys that exist.
@@ -98,7 +124,7 @@ export class Client {
98
124
  * If the key does not exist, it is set to 0 before performing the operation.
99
125
  * If the key exists but cannot be treated as a number, the returned promise will be rejected.
100
126
  *
101
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-incr
127
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-incr
102
128
  *
103
129
  * @param key - key to increment the value of
104
130
  * @returns a promise that resolves to the value of the key after the increment.
@@ -111,7 +137,7 @@ export class Client {
111
137
  * If the key does not exist, it is set to 0 before performing the operation.
112
138
  * If the key exists but cannot be treated as a number, the returned promise will be rejected.
113
139
  *
114
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-incrby
140
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-incrby
115
141
  *
116
142
  * @param key - key to increment the value of
117
143
  * @param increment - amount to increment the value of the key by
@@ -125,7 +151,7 @@ export class Client {
125
151
  * If the key does not exist, it is set to 0 before performing the operation.
126
152
  * If the key exists but cannot be treated as a number, the returned promise will be rejected.
127
153
  *
128
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-decr
154
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-decr
129
155
  *
130
156
  * @param key - key to decrement the value of
131
157
  * @returns a promise that resolves to the value of the key after the decrement.
@@ -138,7 +164,7 @@ export class Client {
138
164
  * If the key does not exist, it is set to 0 before performing the operation.
139
165
  * If the key exists but cannot be treated as a number, the returned promise will be rejected.
140
166
  *
141
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-decrby
167
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-decrby
142
168
  *
143
169
  * @param key - key to decrement the value of
144
170
  * @param decrement - amount to decrement the value of the key by
@@ -151,7 +177,7 @@ export class Client {
151
177
  *
152
178
  * If the database is empty, the returned promise will be rejected.
153
179
  *
154
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-randomkey
180
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-randomkey
155
181
  *
156
182
  * @returns a promise that resolves to a random key.
157
183
  */
@@ -160,7 +186,7 @@ export class Client {
160
186
  /**
161
187
  * Returns the values of all the specified keys.
162
188
  *
163
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-mget
189
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-mget
164
190
  *
165
191
  * @param keys - the keys to get the values of
166
192
  * @returns a promise that resolves to an array of the values of the keys.
@@ -173,7 +199,7 @@ export class Client {
173
199
  * Calling expire with a non-positive timeout value will result in the being deleted rather
174
200
  * than expired.
175
201
  *
176
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-expire
202
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-expire
177
203
  *
178
204
  * @param key - key to set the time to live of
179
205
  * @param seconds - value to set the time to live of the key to (in seconds)
@@ -184,7 +210,7 @@ export class Client {
184
210
  /**
185
211
  * Returns the remaining time to live of a key that has a timeout.
186
212
  *
187
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-ttl
213
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-ttl
188
214
  *
189
215
  * @param key - the key to get the time to live of
190
216
  * @returns a promise that resolves to the time to live of the key, in seconds.
@@ -194,7 +220,7 @@ export class Client {
194
220
  /**
195
221
  * Removes the existing timeout on a key.
196
222
  *
197
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-persist
223
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-persist
198
224
  *
199
225
  * @param key - the key to remove the timeout of.
200
226
  * @returns a promise that resolves to true if the operation succeeded, false otherwise.
@@ -206,7 +232,7 @@ export class Client {
206
232
  *
207
233
  * If the key exists but does not hold a list, the returned promise will be rejected.
208
234
  *
209
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-lpush
235
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-lpush
210
236
  *
211
237
  * @param key - key holding the list to prepend to
212
238
  * @param values - values to prepend to the list
@@ -219,7 +245,7 @@ export class Client {
219
245
  *
220
246
  * If the key exists but does not hold a list, the returned promise will be rejected.
221
247
  *
222
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-rpush
248
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-rpush
223
249
  *
224
250
  * @param key - key holding the list to append to
225
251
  * @param values - values to append to the list
@@ -230,7 +256,7 @@ export class Client {
230
256
  /**
231
257
  * Removes and returns the value at the head of the list stored at key.
232
258
  *
233
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-lpop
259
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-lpop
234
260
  *
235
261
  * @param key - key holding the list to pop the head of
236
262
  * @returns a promise that resolves to the value that was popped.
@@ -240,7 +266,7 @@ export class Client {
240
266
  /**
241
267
  * Removes and returns the value at the tail of the list stored at key.
242
268
  *
243
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-rpop
269
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-rpop
244
270
  *
245
271
  * @param key - key holding the list to pop the tail of
246
272
  * @returns a promise that resolves to the value that was popped.
@@ -253,7 +279,7 @@ export class Client {
253
279
  * The offsets are zero-based. These offsets can be negative numbers indicating
254
280
  * offsets starting at the end of the list.
255
281
  *
256
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-lrange
282
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-lrange
257
283
  *
258
284
  * @param key - key holding the list to get the range of
259
285
  * @param start - index of the first element to return
@@ -268,7 +294,7 @@ export class Client {
268
294
  * The offsets are zero-based. These offsets can be negative numbers indicating
269
295
  * offsets starting at the end of the list.
270
296
  *
271
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-lindex
297
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-lindex
272
298
  *
273
299
  * @param key - key holding the list to get the element of
274
300
  * @param index - index of the element to get
@@ -279,7 +305,7 @@ export class Client {
279
305
  /**
280
306
  * Sets the value of an element in the list stored at key to new value.
281
307
  *
282
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-lset
308
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-lset
283
309
  *
284
310
  * @param key - key holding the list to set the element of
285
311
  * @param index - index of the element to set
@@ -295,7 +321,7 @@ export class Client {
295
321
  * If the `count` is 0, all occurrences of `value` are removed.
296
322
  * If the `count` is negative, elements are removed from the tail of the list (from right to left).
297
323
  *
298
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-lrem
324
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-lrem
299
325
  *
300
326
  * @param key - key holding the list to remove the element of
301
327
  * @param count - the number of elements matching the value to remove
@@ -309,7 +335,7 @@ export class Client {
309
335
  *
310
336
  * If the key does not exist, it is interpreted as an empty list and 0 is returned.
311
337
  *
312
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-llen
338
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-llen
313
339
  *
314
340
  * @param key - key holding the list to get the length of
315
341
  * @returns a promise that resolves to the length of the list.
@@ -322,7 +348,7 @@ export class Client {
322
348
  * If the key does not exist, a new key holding a hash is created.
323
349
  * If the field already exists, it is overwritten.
324
350
  *
325
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-hset
351
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-hset
326
352
  *
327
353
  * @param key - key holding the hash to set the field's value of
328
354
  * @param field - field to set the value of
@@ -337,7 +363,7 @@ export class Client {
337
363
  * If the key does not exist, a new key holding a hash is created.
338
364
  * If the field already exists, the returned promise will be rejected.
339
365
  *
340
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-hsetnx
366
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-hsetnx
341
367
  *
342
368
  * @param key - key holding the hash to set the field's value of
343
369
  * @param field - field to set the value of
@@ -349,7 +375,7 @@ export class Client {
349
375
  /**
350
376
  * Returns the value of the specified hash field.
351
377
  *
352
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-hget
378
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-hget
353
379
  *
354
380
  * @param key - key holding the hash to get the field's value of
355
381
  * @param field - field to get the value of
@@ -360,7 +386,7 @@ export class Client {
360
386
  /**
361
387
  * Deletes the specified fields from the hash stored at key.
362
388
  *
363
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-hdel
389
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-hdel
364
390
  *
365
391
  * @param key - key holding the hash to delete the fields of
366
392
  * @param fields - fields to delete from the hash
@@ -371,7 +397,7 @@ export class Client {
371
397
  /**
372
398
  * Returns all fields and values of the hash stored at key.
373
399
  *
374
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-hgetall
400
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-hgetall
375
401
  *
376
402
  * @param key - the key holding the hash to get the fields of
377
403
  * @returns a promise that resolves to an object of field/value pairs.
@@ -381,7 +407,7 @@ export class Client {
381
407
  /**
382
408
  * Returns all fields of the hash stored at key.
383
409
  *
384
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-hkeys
410
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-hkeys
385
411
  *
386
412
  * @param key - the key holding the hash to get the fields of
387
413
  * @returns a promise that resolves to an array of field names.
@@ -391,7 +417,7 @@ export class Client {
391
417
  /**
392
418
  * Returns all values of the hash stored at key.
393
419
  *
394
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-hvals
420
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-hvals
395
421
  *
396
422
  * @param key - the key holding the hash to get the fields' values of
397
423
  * @returns a promise that resolves to an array of field values.
@@ -401,7 +427,7 @@ export class Client {
401
427
  /**
402
428
  * Return the number of fields contained in the hash stored at key.
403
429
  *
404
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-hlen
430
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-hlen
405
431
  *
406
432
  * @param key - the key holding the hash to get the number of fields of
407
433
  * @returns a promise that resolves to the number of fields in the hash.
@@ -415,7 +441,7 @@ export class Client {
415
441
  * If the field does not exist, it is set to 0 before the operation is performed.
416
442
  * If the field does not hold a nummerical value, the returned promise will be rejected.
417
443
  *
418
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-hincrby
444
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-hincrby
419
445
  *
420
446
  * @param key - the key holding the hash to get the number of fields of
421
447
  * @param field - the hash's field to increment the value of
@@ -430,7 +456,7 @@ export class Client {
430
456
  * Specified elements that are already a member of the set are ignored.
431
457
  * If the key does not exist, a new set is created before adding the specified elements.
432
458
  *
433
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-sadd
459
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-sadd
434
460
  *
435
461
  * @param key - the key holding the set to add a member to
436
462
  * @param members - the members to add to the set
@@ -444,7 +470,7 @@ export class Client {
444
470
  * Specified members that are not a member of this set are ignored.
445
471
  * If key does not exist, it is treated as an empty set and this command returns 0.
446
472
  *
447
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-srem
473
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-srem
448
474
  *
449
475
  * @param key - the key holding the set to remove a member from
450
476
  * @param members - the members to remove from the set
@@ -455,7 +481,7 @@ export class Client {
455
481
  /**
456
482
  * Returns whether or not the specified member is a member of the set stored at key.
457
483
  *
458
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-sismembers
484
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-sismember
459
485
  *
460
486
  * @param key - the key holding the set to check the belonging of
461
487
  * @param member - the member to check the belonging of
@@ -466,7 +492,7 @@ export class Client {
466
492
  /**
467
493
  * Returns the members of the set stored at key.
468
494
  *
469
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-smembers
495
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-smembers
470
496
  *
471
497
  * @param key - the key holding the set to get the members of
472
498
  * @returns a promise that resolves to an array of members in the set.
@@ -476,7 +502,7 @@ export class Client {
476
502
  /**
477
503
  * Returns a random member of the set value stored at key.
478
504
  *
479
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-srandmember
505
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-srandmember
480
506
  *
481
507
  * @param key - the key holding the set to get the random member of
482
508
  * @returns a promise that resolves to a random member of the set.
@@ -486,7 +512,7 @@ export class Client {
486
512
  /**
487
513
  * Pops a random member from the set stored at key.
488
514
  *
489
- * https://k6.io/docs/javascript-api/k6-experimental/redis/client/client-spop
515
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/redis/client/client-spop
490
516
  *
491
517
  * @param key - the key holding the set to pop the random member of
492
518
  * @returns a promise that resolves to the popped member.
@@ -495,114 +521,296 @@ export class Client {
495
521
  }
496
522
 
497
523
  /**
498
- * Options for configuring the redis Client.
524
+ * Represents a Redis connection URL.
525
+ * The URL follows the format: redis[s]://[[username][:password]@][host][:port][/db-number]
526
+ *
527
+ * - `RedisProtocol` indicates the protocol used ('redis' for standard connections, 'rediss' for secure TLS connections).
528
+ * - `RedisUserInfo` optionally includes the username and password for authentication.
529
+ * - The `host` is the IP address or hostname of the Redis server.
530
+ * - `RedisPort` is the port on which the Redis server is listening (optional, defaults to 6379 if not specified).
531
+ * - `RedisDbNumber` specifies a particular database number to connect to (optional).
532
+ */
533
+ export type RedisConnectionURL = `${RedisProtocol}://${RedisUserInfo}${string}${RedisPort}${RedisDbNumber}`;
534
+
535
+ /**
536
+ * Represents the protocol part of a Redis URL.
537
+ * - `redis`: Standard, non-encrypted connections.
538
+ * - `rediss`: Secure connections using TLS.
539
+ */
540
+ export type RedisProtocol = "redis" | "rediss";
541
+
542
+ /**
543
+ * Represents the user authentication information part of a Redis URL.
544
+ * Formats:
545
+ * - `username:password@`: Both username and password are provided for authentication.
546
+ * - `username@`: Only username is provided, no password.
547
+ * - `"": No authentication information is included.
548
+ */
549
+ export type RedisUserInfo = `${string}:${string}@` | `${string}@` | "";
550
+
551
+ export type RedisHost = string;
552
+
553
+ /**
554
+ * Represents the port part of a Redis URL.
555
+ * - `:number`: The port number on which the Redis server is listening.
556
+ * - `"": No port is specified, implying the default port (usually 6379).
557
+ */
558
+ export type RedisPort = `:${number}` | "";
559
+
560
+ /**
561
+ * Represents the database number part of a Redis URL.
562
+ * - `/${number}`: Specifies the database number to connect to.
563
+ * - `"": No database number is specified, implying the default database (usually 0).
564
+ */
565
+ export type RedisDbNumber = `/${number}` | "";
566
+
567
+ /**
568
+ * Represents the configuration options for a Redis client.
499
569
  *
500
- * https://k6.io/docs/javascript-api/k6-experimental/redis/options
570
+ * These options define how the client connects to and interacts with a Redis server or cluster,
571
+ * including authentication, connection settings, and specific Redis features.
501
572
  */
502
- export interface Options {
573
+ export interface RedisClientOptions {
503
574
  /**
504
- * Array of addresses in the 'host:port' defining which connect Redis to connect to.
505
- * Supplying a single entry would connect the client to a single Redis instance.
506
- * Supplying multiple entries would connect the client to a cluster/sentinel nodes.
575
+ * Socket connection options for the Redis client.
576
+ *
577
+ * This includes the host, port, and other socket-level settings such as timeouts and TLS configuration.
507
578
  */
508
- addrs: string[];
579
+ socket: SocketOptions;
509
580
 
510
581
  /**
511
- * The id of the database to be selected after connecting to the server.
512
- * Only used when connecting to a single-node use.
582
+ * Optional username for client authentication.
583
+ *
584
+ * This is used when the Redis server is configured with ACLs (Access Control Lists),
585
+ * requiring a username for authentication in addition to a password.
513
586
  */
514
- db?: number;
587
+ username?: string;
515
588
 
516
589
  /**
517
- * Username to authenticate the client connection with.
590
+ * Optional password for client authentication.
591
+ *
592
+ * If the Redis server is secured with a password, this must be provided to establish a connection.
518
593
  */
519
- username?: number;
594
+ password?: string;
520
595
 
521
596
  /**
522
- * Password to authenticate the client connection with.
597
+ * Optional name to assign to the client connection.
598
+ *
599
+ * This can be used for identifying and tracking connections on the Redis server.
600
+ * It's useful for debugging and monitoring purposes.
523
601
  */
524
- password?: number;
602
+ clientName?: string;
525
603
 
526
604
  /**
527
- * Username to authenticate the client connection with when connecting to a sentinel.
605
+ * The ID of the database to be selected after connecting to the Redis server.
606
+ *
607
+ * Redis supports multiple databases (numbered from 0), allowing separate datasets on the same server instance.
608
+ * This option is typically used when connecting to a single-node setup.
528
609
  */
529
- sentinelUsername?: number;
610
+ database?: number;
530
611
 
531
612
  /**
532
- * Password to authenticate the client connection with when connecting to a sentinel.
613
+ * The name of the master instance to connect to when using Redis Sentinel.
614
+ *
615
+ * Sentinel manages failover in a Redis deployment, and specifying a master name allows the client to connect to the current master.
616
+ * This option is required when connecting through Redis Sentinel.
533
617
  */
534
- sentinelPassword?: number;
618
+ masterName?: string;
535
619
 
536
620
  /**
537
- * The name of the master to connect to when connecting to a Redis cluster.
621
+ * Optional username for client authentication with Redis Sentinel.
622
+ *
623
+ * If the Sentinel servers are secured with ACLs, this username is used for authentication.
538
624
  */
539
- masterName?: number;
625
+ sentinelUsername?: string;
540
626
 
541
627
  /**
542
- * The maximum number of retries to attempt when connecting to a Redis server before giving up.
628
+ * Optional password for client authentication with Redis Sentinel.
629
+ *
630
+ * If the Sentinel servers are secured with a password, it must be provided to connect successfully.
543
631
  */
544
- maxRetries?: number;
632
+ sentinelPassword?: string;
545
633
 
546
634
  /**
547
- * The minimum amount of time to wait between retries when connecting to a Redis server.
635
+ * Optional configuration for connecting to a Redis Cluster.
636
+ *
637
+ * If the client is connecting to a Redis Cluster, this option provides cluster-specific settings such as node addresses and routing options.
548
638
  */
549
- minRetryBackoff?: number;
639
+ cluster?: ClusterOptions;
640
+ }
550
641
 
642
+ /**
643
+ * Represents the configuration options for a socket connection to a Redis server.
644
+ *
645
+ * These options allow fine-tuning of the connection properties, timeouts, and TLS settings.
646
+ */
647
+ export interface SocketOptions {
551
648
  /**
552
- * The maximum amount of time to wait between retries when connecting to a Redis server.
649
+ * The IP address or hostname of the Redis server.
650
+ * This should be a valid, resolvable address or hostname used to establish the connection.
553
651
  */
554
- maxRetryBackoff?: number;
652
+ host: string;
555
653
 
556
654
  /**
557
- * The maximum amount of time to wait for a connection to a Redis server to be established.
655
+ * The port number on which the Redis server is listening.
656
+ *
657
+ * If omitted, a default port (typically 6379 for Redis) will be used.
658
+ */
659
+ port?: number;
660
+
661
+ /**
662
+ * Optional configuration for TLS (Transport Layer Security).
663
+ *
664
+ * This is used to establish a secure, encrypted connection to the Redis server.
665
+ * If provided, the connection will use TLS; otherwise, it will be a regular, non-encrypted connection.
666
+ */
667
+ tls?: TLSOptions;
668
+
669
+ /**
670
+ * The maximum amount of time, in milliseconds, to wait for a connection attempt to the Redis server to succeed.
671
+ *
672
+ * If the connection is not established within this time frame, the attempt will be aborted.
673
+ * This helps in avoiding long waits if the server is not reachable.
558
674
  */
559
675
  dialTimeout?: number;
560
676
 
561
677
  /**
562
- * The maximum amount of time to wait for socket reads to succeed.
563
- * Use `-1` for no timeout.
678
+ * The maximum amount of time, in milliseconds, the client will wait for a read operation to complete.
679
+ *
680
+ * A value of `-1` indicates no timeout, meaning the client will wait indefinitely.
681
+ * Setting a read timeout can prevent indefinitely blocking operations if the server becomes unresponsive.
564
682
  */
565
683
  readTimeout?: number;
566
684
 
567
685
  /**
568
- * The maximum amount of time to wait for a socket write to succeed.
569
- * Use `-1` for no timeout.
686
+ * The maximum amount of time, in milliseconds, the client will wait for a write operation to complete.
687
+ *
688
+ * A value of `-1` indicates no timeout, allowing the client to wait indefinitely.
689
+ * Similar to readTimeout, this can prevent blocking in case of server issues.
570
690
  */
571
691
  writeTimeout?: number;
572
692
 
573
693
  /**
574
- * The maximum number of socket connections to keep open in the connection pool.
694
+ * The maximum number of socket connections that can be kept open in the pool.
695
+ * A larger pool size can handle more concurrent connections, but also uses more resources.
575
696
  */
576
697
  poolSize?: number;
577
698
 
578
699
  /**
579
- * The minimum number of idle connections to keep open in the connection pool.
700
+ * The minimum number of idle connections that the pool maintains for faster access.
701
+ *
702
+ * Keeping some connections idle can improve performance by avoiding the need to establish new connections.
580
703
  */
581
704
  minIdleConns?: number;
582
705
 
583
706
  /**
584
- * The maximum number of idle connections to keep open in the connection pool.
585
- */
586
- maxIdleConns?: number;
587
-
588
- /**
589
- * The maximum amount of time a connection can be idle in the connection pool before being closed.
707
+ * The maximum amount of time, in milliseconds, a connection can stay idle in the pool before being closed.
708
+ *
709
+ * This can help in cycling connections and preventing stale connections.
590
710
  */
591
711
  maxConnAge?: number;
592
712
 
593
713
  /**
594
- * The maximum amount of time to wait for a connection to the Redis server to be returned from the pool.
714
+ * The maximum amount of time, in milliseconds, to wait for a connection from the pool.
715
+ *
716
+ * If no connections are available within this time frame, the request for a connection will fail.
717
+ * This prevents indefinite blocking when all connections are in use.
595
718
  */
596
719
  poolTimeout?: number;
597
720
 
598
721
  /**
599
- * The maximum amount of time the client waits for a connection to become active before timing out.
722
+ * The maximum amount of time, in milliseconds, a connection can be idle in the pool before being considered for closure.
723
+ *
724
+ * This helps in keeping the pool fresh and closing unused connections.
600
725
  */
601
726
  idleTimeout?: number;
602
727
 
603
728
  /**
604
- * The frequency at which the client checks for idle connections in the connection pool.
605
- * Use `-1` to disable the checks.
729
+ * The frequency, in milliseconds, at which the client checks for idle connections in the pool.
730
+ *
731
+ * A value of `-1` disables these checks. Regularly checking for idle connections helps in maintaining a healthy connection pool.
606
732
  */
607
733
  idleCheckFrequency?: number;
608
734
  }
735
+
736
+ /**
737
+ * Represents the options for configuring TLS (Transport Layer Security) for a Redis connection.
738
+ * This configuration is essential for establishing a secure connection using SSL/TLS,
739
+ * which ensures data is encrypted during transmission.
740
+ */
741
+ export interface TLSOptions {
742
+ /**
743
+ * Specifies one or multiple Certificate Authority (CA) certificates to use for validating the server certificate.
744
+ *
745
+ * The CA certificates are essential for ensuring that the server's certificate is issued by a trusted authority.
746
+ * This is an array of ArrayBuffer, where each ArrayBuffer represents a CA certificate in a binary format.
747
+ */
748
+ ca: ArrayBuffer[];
749
+
750
+ /**
751
+ * An optional client certificate used for mutual TLS authentication.
752
+ *
753
+ * Providing a client certificate is part of mutual TLS (mTLS), where both the client and the server authenticate each other.
754
+ * This property should be an ArrayBuffer representing the client's certificate in a binary format.
755
+ * If this property is omitted, the client will not use a certificate for authentication.
756
+ */
757
+ cert?: ArrayBuffer;
758
+
759
+ /**
760
+ * An optional private key associated with the client certificate.
761
+ *
762
+ * This key is required if a client certificate is provided (via the `cert` property).
763
+ * The private key must correspond to the public key in the client certificate and should be in a binary format represented by an ArrayBuffer.
764
+ * If this property is omitted but a client certificate is provided, the connection attempt will fail due to the lack of a corresponding private key.
765
+ */
766
+ key?: ArrayBuffer;
767
+ }
768
+
769
+ /**
770
+ * Represents the configuration options for a Redis Cluster client.
771
+ *
772
+ * These options define the behavior of the client when connecting to and interacting with a Redis Cluster.
773
+ */
774
+ export interface ClusterOptions {
775
+ /**
776
+ * The maximum number of redirects the client will follow when a command is redirected.
777
+ *
778
+ * In a Redis Cluster, certain commands may be redirected to other nodes. This option limits the number of such redirections.
779
+ * If this value is not set, a default value (typically defined by the client library) will be used.
780
+ */
781
+ maxRedirects?: number;
782
+
783
+ /**
784
+ * Determines if the client operates in read-only mode.
785
+ *
786
+ * When set to true, the client sends read commands to replica nodes, potentially improving read scalability.
787
+ * This is useful in a cluster setup where you want to distribute read operations across multiple replicas.
788
+ */
789
+ readOnly?: boolean;
790
+
791
+ /**
792
+ * Enables routing read commands by latency.
793
+ *
794
+ * when true, the client attempts to route read commands to the node with the lowest latency.
795
+ * This can optimize read performance by utilizing the fastest available node.
796
+ */
797
+ routeByLatency?: boolean;
798
+
799
+ /**
800
+ * Enables random routing for read commands.
801
+ *
802
+ * When true, read commands are sent to random nodes in the cluster, potentially distributing the load more evenly.
803
+ * This can be beneficial in scenarios where distributing read operations evenly is more important than routing based on latency.
804
+ */
805
+ routeRandomly?: boolean;
806
+
807
+ /**
808
+ * A list of nodes in the Redis Cluster.
809
+ *
810
+ * This can either be a list of connection URLs or a list of socket options for each node.
811
+ * The client uses this list to initially connect to the cluster and discover other nodes.
812
+ *
813
+ * Each node can be specified as a `RedisConnectionURL` string (e.g., 'redis://host:port') or as a `SocketOptions` object defining host and port.
814
+ */
815
+ nodes: RedisConnectionURL[] | SocketOptions[];
816
+ }