@@ -79,14 +79,14 @@ export interface RedisClientOptions<
79
79
pingInterval ?: number ;
80
80
/**
81
81
* Default command options to be applied to all commands executed through this client.
82
- *
82
+ *
83
83
* These options can be overridden on a per-command basis when calling specific commands.
84
- *
84
+ *
85
85
* @property {symbol } [chainId] - Identifier for chaining commands together
86
86
* @property {boolean } [asap] - When true, the command is executed as soon as possible
87
87
* @property {AbortSignal } [abortSignal] - AbortSignal to cancel the command
88
88
* @property {TypeMapping } [typeMapping] - Custom type mappings between RESP and JavaScript types
89
- *
89
+ *
90
90
* @example Setting default command options
91
91
* ```
92
92
* const client = createClient({
@@ -102,33 +102,33 @@ export interface RedisClientOptions<
102
102
commandOptions ?: CommandOptions < TYPE_MAPPING > ;
103
103
/**
104
104
* Client Side Caching configuration.
105
- *
106
- * Enables Redis Servers and Clients to work together to cache results from commands
105
+ *
106
+ * Enables Redis Servers and Clients to work together to cache results from commands
107
107
* sent to a server. The server will notify the client when cached results are no longer valid.
108
- *
108
+ *
109
109
* Note: Client Side Caching is only supported with RESP3.
110
- *
110
+ *
111
111
* @example Anonymous cache configuration
112
112
* ```
113
113
* const client = createClient({
114
- * RESP: 3,
114
+ * RESP: 3,
115
115
* clientSideCache: {
116
116
* ttl: 0,
117
117
* maxEntries: 0,
118
- * evictPolicy: "LRU"
118
+ * evictPolicy: "LRU"
119
119
* }
120
120
* });
121
121
* ```
122
- *
122
+ *
123
123
* @example Using a controllable cache
124
124
* ```
125
- * const cache = new BasicClientSideCache({
126
- * ttl: 0,
127
- * maxEntries: 0,
128
- * evictPolicy: "LRU"
125
+ * const cache = new BasicClientSideCache({
126
+ * ttl: 0,
127
+ * maxEntries: 0,
128
+ * evictPolicy: "LRU"
129
129
* });
130
130
* const client = createClient({
131
- * RESP: 3,
131
+ * RESP: 3,
132
132
* clientSideCache: cache
133
133
* });
134
134
* ```
@@ -140,36 +140,36 @@ type WithCommands<
140
140
RESP extends RespVersions ,
141
141
TYPE_MAPPING extends TypeMapping
142
142
> = {
143
- [ P in keyof typeof COMMANDS ] : CommandSignature < ( typeof COMMANDS ) [ P ] , RESP , TYPE_MAPPING > ;
144
- } ;
143
+ [ P in keyof typeof COMMANDS ] : CommandSignature < ( typeof COMMANDS ) [ P ] , RESP , TYPE_MAPPING > ;
144
+ } ;
145
145
146
146
type WithModules <
147
147
M extends RedisModules ,
148
148
RESP extends RespVersions ,
149
149
TYPE_MAPPING extends TypeMapping
150
150
> = {
151
- [ P in keyof M ] : {
152
- [ C in keyof M [ P ] ] : CommandSignature < M [ P ] [ C ] , RESP , TYPE_MAPPING > ;
151
+ [ P in keyof M ] : {
152
+ [ C in keyof M [ P ] ] : CommandSignature < M [ P ] [ C ] , RESP , TYPE_MAPPING > ;
153
+ } ;
153
154
} ;
154
- } ;
155
155
156
156
type WithFunctions <
157
157
F extends RedisFunctions ,
158
158
RESP extends RespVersions ,
159
159
TYPE_MAPPING extends TypeMapping
160
160
> = {
161
- [ L in keyof F ] : {
162
- [ C in keyof F [ L ] ] : CommandSignature < F [ L ] [ C ] , RESP , TYPE_MAPPING > ;
161
+ [ L in keyof F ] : {
162
+ [ C in keyof F [ L ] ] : CommandSignature < F [ L ] [ C ] , RESP , TYPE_MAPPING > ;
163
+ } ;
163
164
} ;
164
- } ;
165
165
166
166
type WithScripts <
167
167
S extends RedisScripts ,
168
168
RESP extends RespVersions ,
169
169
TYPE_MAPPING extends TypeMapping
170
170
> = {
171
- [ P in keyof S ] : CommandSignature < S [ P ] , RESP , TYPE_MAPPING > ;
172
- } ;
171
+ [ P in keyof S ] : CommandSignature < S [ P ] , RESP , TYPE_MAPPING > ;
172
+ } ;
173
173
174
174
export type RedisClientExtensions <
175
175
M extends RedisModules = { } ,
@@ -178,11 +178,11 @@ export type RedisClientExtensions<
178
178
RESP extends RespVersions = 2 ,
179
179
TYPE_MAPPING extends TypeMapping = { }
180
180
> = (
181
- WithCommands < RESP , TYPE_MAPPING > &
182
- WithModules < M , RESP , TYPE_MAPPING > &
183
- WithFunctions < F , RESP , TYPE_MAPPING > &
184
- WithScripts < S , RESP , TYPE_MAPPING >
185
- ) ;
181
+ WithCommands < RESP , TYPE_MAPPING > &
182
+ WithModules < M , RESP , TYPE_MAPPING > &
183
+ WithFunctions < F , RESP , TYPE_MAPPING > &
184
+ WithScripts < S , RESP , TYPE_MAPPING >
185
+ ) ;
186
186
187
187
export type RedisClientType <
188
188
M extends RedisModules = { } ,
@@ -191,9 +191,9 @@ export type RedisClientType<
191
191
RESP extends RespVersions = 2 ,
192
192
TYPE_MAPPING extends TypeMapping = { }
193
193
> = (
194
- RedisClient < M , F , S , RESP , TYPE_MAPPING > &
195
- RedisClientExtensions < M , F , S , RESP , TYPE_MAPPING >
196
- ) ;
194
+ RedisClient < M , F , S , RESP , TYPE_MAPPING > &
195
+ RedisClientExtensions < M , F , S , RESP , TYPE_MAPPING >
196
+ ) ;
197
197
198
198
type ProxyClient = RedisClient < any , any , any , any , any > ;
199
199
@@ -353,8 +353,8 @@ export default class RedisClient<
353
353
#monitorCallback?: MonitorCallback < TYPE_MAPPING > ;
354
354
private _self = this ;
355
355
private _commandOptions ?: CommandOptions < TYPE_MAPPING > ;
356
- // flag used to annotate that the client
357
- // was in a watch transaction when
356
+ // flag used to annotate that the client
357
+ // was in a watch transaction when
358
358
// a topology change occured
359
359
#dirtyWatch?: string ;
360
360
#watchEpoch?: number ;
@@ -409,7 +409,7 @@ export default class RedisClient<
409
409
410
410
constructor ( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) {
411
411
super ( ) ;
412
-
412
+ this . #validateOptions ( options )
413
413
this . #options = this . #initiateOptions( options ) ;
414
414
this . #queue = this . #initiateQueue( ) ;
415
415
this . #socket = this . #initiateSocket( ) ;
@@ -425,6 +425,12 @@ export default class RedisClient<
425
425
}
426
426
}
427
427
428
+ #validateOptions( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) {
429
+ if ( options ?. clientSideCache && options ?. RESP !== 3 ) {
430
+ throw new Error ( 'Client Side Caching is only supported with RESP3' ) ;
431
+ }
432
+
433
+ }
428
434
#initiateOptions( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > | undefined {
429
435
430
436
// Convert username/password to credentialsProvider if no credentialsProvider is already in place
@@ -482,7 +488,7 @@ export default class RedisClient<
482
488
}
483
489
}
484
490
485
- #subscribeForStreamingCredentials( cp : StreamingCredentialsProvider ) : Promise < [ BasicAuth , Disposable ] > {
491
+ #subscribeForStreamingCredentials( cp : StreamingCredentialsProvider ) : Promise < [ BasicAuth , Disposable ] > {
486
492
return cp . subscribe ( {
487
493
onNext : credentials => {
488
494
this . reAuthenticate ( credentials ) . catch ( error => {
@@ -517,7 +523,7 @@ export default class RedisClient<
517
523
518
524
if ( cp && cp . type === 'streaming-credentials-provider' ) {
519
525
520
- const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
526
+ const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
521
527
this . #credentialsSubscription = disposable ;
522
528
523
529
if ( credentials . password ) {
@@ -553,7 +559,7 @@ export default class RedisClient<
553
559
554
560
if ( cp && cp . type === 'streaming-credentials-provider' ) {
555
561
556
- const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
562
+ const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
557
563
this . #credentialsSubscription = disposable ;
558
564
559
565
if ( credentials . username || credentials . password ) {
@@ -1014,7 +1020,7 @@ export default class RedisClient<
1014
1020
* @internal
1015
1021
*/
1016
1022
async _executePipeline (
1017
- commands : Array < RedisMultiQueuedCommand > ,
1023
+ commands : Array < RedisMultiQueuedCommand > ,
1018
1024
selectedDB ?: number
1019
1025
) {
1020
1026
if ( ! this . _self . #socket. isOpen ) {
@@ -1065,8 +1071,8 @@ export default class RedisClient<
1065
1071
const typeMapping = this . _commandOptions ?. typeMapping ;
1066
1072
const chainId = Symbol ( 'MULTI Chain' ) ;
1067
1073
const promises = [
1068
- this . _self . #queue. addCommand ( [ 'MULTI' ] , { chainId } ) ,
1069
- ] ;
1074
+ this . _self . #queue. addCommand ( [ 'MULTI' ] , { chainId } ) ,
1075
+ ] ;
1070
1076
1071
1077
for ( const { args } of commands ) {
1072
1078
promises . push (
0 commit comments