@@ -80,14 +80,14 @@ export interface RedisClientOptions<
8080 pingInterval ?: number ;
8181 /**
8282 * Default command options to be applied to all commands executed through this client.
83- *
83+ *
8484 * These options can be overridden on a per-command basis when calling specific commands.
85- *
85+ *
8686 * @property {symbol } [chainId] - Identifier for chaining commands together
8787 * @property {boolean } [asap] - When true, the command is executed as soon as possible
8888 * @property {AbortSignal } [abortSignal] - AbortSignal to cancel the command
8989 * @property {TypeMapping } [typeMapping] - Custom type mappings between RESP and JavaScript types
90- *
90+ *
9191 * @example Setting default command options
9292 * ```
9393 * const client = createClient({
@@ -103,33 +103,33 @@ export interface RedisClientOptions<
103103 commandOptions ?: CommandOptions < TYPE_MAPPING > ;
104104 /**
105105 * 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
108108 * sent to a server. The server will notify the client when cached results are no longer valid.
109- *
109+ *
110110 * Note: Client Side Caching is only supported with RESP3.
111- *
111+ *
112112 * @example Anonymous cache configuration
113113 * ```
114114 * const client = createClient({
115- * RESP: 3,
115+ * RESP: 3,
116116 * clientSideCache: {
117117 * ttl: 0,
118118 * maxEntries: 0,
119- * evictPolicy: "LRU"
119+ * evictPolicy: "LRU"
120120 * }
121121 * });
122122 * ```
123- *
123+ *
124124 * @example Using a controllable cache
125125 * ```
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"
130130 * });
131131 * const client = createClient({
132- * RESP: 3,
132+ * RESP: 3,
133133 * clientSideCache: cache
134134 * });
135135 * ```
@@ -141,36 +141,36 @@ type WithCommands<
141141 RESP extends RespVersions ,
142142 TYPE_MAPPING extends TypeMapping
143143> = {
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+ } ;
146146
147147type WithModules <
148148 M extends RedisModules ,
149149 RESP extends RespVersions ,
150150 TYPE_MAPPING extends TypeMapping
151151> = {
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+ } ;
154155 } ;
155- } ;
156156
157157type WithFunctions <
158158 F extends RedisFunctions ,
159159 RESP extends RespVersions ,
160160 TYPE_MAPPING extends TypeMapping
161161> = {
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+ } ;
164165 } ;
165- } ;
166166
167167type WithScripts <
168168 S extends RedisScripts ,
169169 RESP extends RespVersions ,
170170 TYPE_MAPPING extends TypeMapping
171171> = {
172- [ P in keyof S ] : CommandSignature < S [ P ] , RESP , TYPE_MAPPING > ;
173- } ;
172+ [ P in keyof S ] : CommandSignature < S [ P ] , RESP , TYPE_MAPPING > ;
173+ } ;
174174
175175export type RedisClientExtensions <
176176 M extends RedisModules = { } ,
@@ -179,11 +179,11 @@ export type RedisClientExtensions<
179179 RESP extends RespVersions = 2 ,
180180 TYPE_MAPPING extends TypeMapping = { }
181181> = (
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+ ) ;
187187
188188export type RedisClientType <
189189 M extends RedisModules = { } ,
@@ -192,9 +192,9 @@ export type RedisClientType<
192192 RESP extends RespVersions = 2 ,
193193 TYPE_MAPPING extends TypeMapping = { }
194194> = (
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+ ) ;
198198
199199type ProxyClient = RedisClient < any , any , any , any , any > ;
200200
@@ -363,8 +363,8 @@ export default class RedisClient<
363363 #monitorCallback?: MonitorCallback < TYPE_MAPPING > ;
364364 private _self = this ;
365365 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
368368 // a topology change occured
369369 #dirtyWatch?: string ;
370370 #watchEpoch?: number ;
@@ -419,7 +419,7 @@ export default class RedisClient<
419419
420420 constructor ( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) {
421421 super ( ) ;
422-
422+ this . #validateOptions ( options )
423423 this . #options = this . #initiateOptions( options ) ;
424424 this . #queue = this . #initiateQueue( ) ;
425425 this . #socket = this . #initiateSocket( ) ;
@@ -435,6 +435,12 @@ export default class RedisClient<
435435 }
436436 }
437437
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+ }
438444 #initiateOptions( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > | undefined {
439445
440446 // Convert username/password to credentialsProvider if no credentialsProvider is already in place
@@ -492,7 +498,7 @@ export default class RedisClient<
492498 }
493499 }
494500
495- #subscribeForStreamingCredentials( cp : StreamingCredentialsProvider ) : Promise < [ BasicAuth , Disposable ] > {
501+ #subscribeForStreamingCredentials( cp : StreamingCredentialsProvider ) : Promise < [ BasicAuth , Disposable ] > {
496502 return cp . subscribe ( {
497503 onNext : credentials => {
498504 this . reAuthenticate ( credentials ) . catch ( error => {
@@ -527,7 +533,7 @@ export default class RedisClient<
527533
528534 if ( cp && cp . type === 'streaming-credentials-provider' ) {
529535
530- const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
536+ const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
531537 this . #credentialsSubscription = disposable ;
532538
533539 if ( credentials . password ) {
@@ -563,7 +569,7 @@ export default class RedisClient<
563569
564570 if ( cp && cp . type === 'streaming-credentials-provider' ) {
565571
566- const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
572+ const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
567573 this . #credentialsSubscription = disposable ;
568574
569575 if ( credentials . username || credentials . password ) {
@@ -1024,7 +1030,7 @@ export default class RedisClient<
10241030 * @internal
10251031 */
10261032 async _executePipeline (
1027- commands : Array < RedisMultiQueuedCommand > ,
1033+ commands : Array < RedisMultiQueuedCommand > ,
10281034 selectedDB ?: number
10291035 ) {
10301036 if ( ! this . _self . #socket. isOpen ) {
@@ -1075,8 +1081,8 @@ export default class RedisClient<
10751081 const typeMapping = this . _commandOptions ?. typeMapping ;
10761082 const chainId = Symbol ( 'MULTI Chain' ) ;
10771083 const promises = [
1078- this . _self . #queue. addCommand ( [ 'MULTI' ] , { chainId } ) ,
1079- ] ;
1084+ this . _self . #queue. addCommand ( [ 'MULTI' ] , { chainId } ) ,
1085+ ] ;
10801086
10811087 for ( const { args } of commands ) {
10821088 promises . push (
0 commit comments