@@ -80,14 +80,14 @@ export interface RedisClientOptions<
80
80
pingInterval ?: number ;
81
81
/**
82
82
* Default command options to be applied to all commands executed through this client.
83
- *
83
+ *
84
84
* These options can be overridden on a per-command basis when calling specific commands.
85
- *
85
+ *
86
86
* @property {symbol } [chainId] - Identifier for chaining commands together
87
87
* @property {boolean } [asap] - When true, the command is executed as soon as possible
88
88
* @property {AbortSignal } [abortSignal] - AbortSignal to cancel the command
89
89
* @property {TypeMapping } [typeMapping] - Custom type mappings between RESP and JavaScript types
90
- *
90
+ *
91
91
* @example Setting default command options
92
92
* ```
93
93
* const client = createClient({
@@ -103,33 +103,33 @@ export interface RedisClientOptions<
103
103
commandOptions ?: CommandOptions < TYPE_MAPPING > ;
104
104
/**
105
105
* Client Side Caching configuration.
106
- *
107
- * Enables Redis Servers and Clients to work together to cache results from commands
106
+ *
107
+ * Enables Redis Servers and Clients to work together to cache results from commands
108
108
* sent to a server. The server will notify the client when cached results are no longer valid.
109
- *
109
+ *
110
110
* Note: Client Side Caching is only supported with RESP3.
111
- *
111
+ *
112
112
* @example Anonymous cache configuration
113
113
* ```
114
114
* const client = createClient({
115
- * RESP: 3,
115
+ * RESP: 3,
116
116
* clientSideCache: {
117
117
* ttl: 0,
118
118
* maxEntries: 0,
119
- * evictPolicy: "LRU"
119
+ * evictPolicy: "LRU"
120
120
* }
121
121
* });
122
122
* ```
123
- *
123
+ *
124
124
* @example Using a controllable cache
125
125
* ```
126
- * const cache = new BasicClientSideCache({
127
- * ttl: 0,
128
- * maxEntries: 0,
129
- * evictPolicy: "LRU"
126
+ * const cache = new BasicClientSideCache({
127
+ * ttl: 0,
128
+ * maxEntries: 0,
129
+ * evictPolicy: "LRU"
130
130
* });
131
131
* const client = createClient({
132
- * RESP: 3,
132
+ * RESP: 3,
133
133
* clientSideCache: cache
134
134
* });
135
135
* ```
@@ -141,36 +141,36 @@ type WithCommands<
141
141
RESP extends RespVersions ,
142
142
TYPE_MAPPING extends TypeMapping
143
143
> = {
144
- [ P in keyof typeof COMMANDS ] : CommandSignature < ( typeof COMMANDS ) [ P ] , RESP , TYPE_MAPPING > ;
145
- } ;
144
+ [ P in keyof typeof COMMANDS ] : CommandSignature < ( typeof COMMANDS ) [ P ] , RESP , TYPE_MAPPING > ;
145
+ } ;
146
146
147
147
type WithModules <
148
148
M extends RedisModules ,
149
149
RESP extends RespVersions ,
150
150
TYPE_MAPPING extends TypeMapping
151
151
> = {
152
- [ P in keyof M ] : {
153
- [ C in keyof M [ P ] ] : CommandSignature < M [ P ] [ C ] , RESP , TYPE_MAPPING > ;
152
+ [ P in keyof M ] : {
153
+ [ C in keyof M [ P ] ] : CommandSignature < M [ P ] [ C ] , RESP , TYPE_MAPPING > ;
154
+ } ;
154
155
} ;
155
- } ;
156
156
157
157
type WithFunctions <
158
158
F extends RedisFunctions ,
159
159
RESP extends RespVersions ,
160
160
TYPE_MAPPING extends TypeMapping
161
161
> = {
162
- [ L in keyof F ] : {
163
- [ C in keyof F [ L ] ] : CommandSignature < F [ L ] [ C ] , RESP , TYPE_MAPPING > ;
162
+ [ L in keyof F ] : {
163
+ [ C in keyof F [ L ] ] : CommandSignature < F [ L ] [ C ] , RESP , TYPE_MAPPING > ;
164
+ } ;
164
165
} ;
165
- } ;
166
166
167
167
type WithScripts <
168
168
S extends RedisScripts ,
169
169
RESP extends RespVersions ,
170
170
TYPE_MAPPING extends TypeMapping
171
171
> = {
172
- [ P in keyof S ] : CommandSignature < S [ P ] , RESP , TYPE_MAPPING > ;
173
- } ;
172
+ [ P in keyof S ] : CommandSignature < S [ P ] , RESP , TYPE_MAPPING > ;
173
+ } ;
174
174
175
175
export type RedisClientExtensions <
176
176
M extends RedisModules = { } ,
@@ -179,11 +179,11 @@ export type RedisClientExtensions<
179
179
RESP extends RespVersions = 2 ,
180
180
TYPE_MAPPING extends TypeMapping = { }
181
181
> = (
182
- WithCommands < RESP , TYPE_MAPPING > &
183
- WithModules < M , RESP , TYPE_MAPPING > &
184
- WithFunctions < F , RESP , TYPE_MAPPING > &
185
- WithScripts < S , RESP , TYPE_MAPPING >
186
- ) ;
182
+ WithCommands < RESP , TYPE_MAPPING > &
183
+ WithModules < M , RESP , TYPE_MAPPING > &
184
+ WithFunctions < F , RESP , TYPE_MAPPING > &
185
+ WithScripts < S , RESP , TYPE_MAPPING >
186
+ ) ;
187
187
188
188
export type RedisClientType <
189
189
M extends RedisModules = { } ,
@@ -192,9 +192,9 @@ export type RedisClientType<
192
192
RESP extends RespVersions = 2 ,
193
193
TYPE_MAPPING extends TypeMapping = { }
194
194
> = (
195
- RedisClient < M , F , S , RESP , TYPE_MAPPING > &
196
- RedisClientExtensions < M , F , S , RESP , TYPE_MAPPING >
197
- ) ;
195
+ RedisClient < M , F , S , RESP , TYPE_MAPPING > &
196
+ RedisClientExtensions < M , F , S , RESP , TYPE_MAPPING >
197
+ ) ;
198
198
199
199
type ProxyClient = RedisClient < any , any , any , any , any > ;
200
200
@@ -363,8 +363,8 @@ export default class RedisClient<
363
363
#monitorCallback?: MonitorCallback < TYPE_MAPPING > ;
364
364
private _self = this ;
365
365
private _commandOptions ?: CommandOptions < TYPE_MAPPING > ;
366
- // flag used to annotate that the client
367
- // was in a watch transaction when
366
+ // flag used to annotate that the client
367
+ // was in a watch transaction when
368
368
// a topology change occured
369
369
#dirtyWatch?: string ;
370
370
#watchEpoch?: number ;
@@ -419,7 +419,7 @@ export default class RedisClient<
419
419
420
420
constructor ( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) {
421
421
super ( ) ;
422
-
422
+ this . #validateOptions ( options )
423
423
this . #options = this . #initiateOptions( options ) ;
424
424
this . #queue = this . #initiateQueue( ) ;
425
425
this . #socket = this . #initiateSocket( ) ;
@@ -435,6 +435,12 @@ export default class RedisClient<
435
435
}
436
436
}
437
437
438
+ #validateOptions( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) {
439
+ if ( options ?. clientSideCache && options ?. RESP !== 3 ) {
440
+ throw new Error ( 'Client Side Caching is only supported with RESP3' ) ;
441
+ }
442
+
443
+ }
438
444
#initiateOptions( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > | undefined {
439
445
440
446
// Convert username/password to credentialsProvider if no credentialsProvider is already in place
@@ -492,7 +498,7 @@ export default class RedisClient<
492
498
}
493
499
}
494
500
495
- #subscribeForStreamingCredentials( cp : StreamingCredentialsProvider ) : Promise < [ BasicAuth , Disposable ] > {
501
+ #subscribeForStreamingCredentials( cp : StreamingCredentialsProvider ) : Promise < [ BasicAuth , Disposable ] > {
496
502
return cp . subscribe ( {
497
503
onNext : credentials => {
498
504
this . reAuthenticate ( credentials ) . catch ( error => {
@@ -527,7 +533,7 @@ export default class RedisClient<
527
533
528
534
if ( cp && cp . type === 'streaming-credentials-provider' ) {
529
535
530
- const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
536
+ const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
531
537
this . #credentialsSubscription = disposable ;
532
538
533
539
if ( credentials . password ) {
@@ -563,7 +569,7 @@ export default class RedisClient<
563
569
564
570
if ( cp && cp . type === 'streaming-credentials-provider' ) {
565
571
566
- const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
572
+ const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
567
573
this . #credentialsSubscription = disposable ;
568
574
569
575
if ( credentials . username || credentials . password ) {
@@ -1024,7 +1030,7 @@ export default class RedisClient<
1024
1030
* @internal
1025
1031
*/
1026
1032
async _executePipeline (
1027
- commands : Array < RedisMultiQueuedCommand > ,
1033
+ commands : Array < RedisMultiQueuedCommand > ,
1028
1034
selectedDB ?: number
1029
1035
) {
1030
1036
if ( ! this . _self . #socket. isOpen ) {
@@ -1075,8 +1081,8 @@ export default class RedisClient<
1075
1081
const typeMapping = this . _commandOptions ?. typeMapping ;
1076
1082
const chainId = Symbol ( 'MULTI Chain' ) ;
1077
1083
const promises = [
1078
- this . _self . #queue. addCommand ( [ 'MULTI' ] , { chainId } ) ,
1079
- ] ;
1084
+ this . _self . #queue. addCommand ( [ 'MULTI' ] , { chainId } ) ,
1085
+ ] ;
1080
1086
1081
1087
for ( const { args } of commands ) {
1082
1088
promises . push (
0 commit comments