@@ -79,14 +79,14 @@ export interface RedisClientOptions<
7979 pingInterval ?: number ;
8080 /**
8181 * Default command options to be applied to all commands executed through this client.
82- *
82+ *
8383 * These options can be overridden on a per-command basis when calling specific commands.
84- *
84+ *
8585 * @property {symbol } [chainId] - Identifier for chaining commands together
8686 * @property {boolean } [asap] - When true, the command is executed as soon as possible
8787 * @property {AbortSignal } [abortSignal] - AbortSignal to cancel the command
8888 * @property {TypeMapping } [typeMapping] - Custom type mappings between RESP and JavaScript types
89- *
89+ *
9090 * @example Setting default command options
9191 * ```
9292 * const client = createClient({
@@ -102,33 +102,33 @@ export interface RedisClientOptions<
102102 commandOptions ?: CommandOptions < TYPE_MAPPING > ;
103103 /**
104104 * 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
107107 * sent to a server. The server will notify the client when cached results are no longer valid.
108- *
108+ *
109109 * Note: Client Side Caching is only supported with RESP3.
110- *
110+ *
111111 * @example Anonymous cache configuration
112112 * ```
113113 * const client = createClient({
114- * RESP: 3,
114+ * RESP: 3,
115115 * clientSideCache: {
116116 * ttl: 0,
117117 * maxEntries: 0,
118- * evictPolicy: "LRU"
118+ * evictPolicy: "LRU"
119119 * }
120120 * });
121121 * ```
122- *
122+ *
123123 * @example Using a controllable cache
124124 * ```
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"
129129 * });
130130 * const client = createClient({
131- * RESP: 3,
131+ * RESP: 3,
132132 * clientSideCache: cache
133133 * });
134134 * ```
@@ -140,36 +140,36 @@ type WithCommands<
140140 RESP extends RespVersions ,
141141 TYPE_MAPPING extends TypeMapping
142142> = {
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+ } ;
145145
146146type WithModules <
147147 M extends RedisModules ,
148148 RESP extends RespVersions ,
149149 TYPE_MAPPING extends TypeMapping
150150> = {
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+ } ;
153154 } ;
154- } ;
155155
156156type WithFunctions <
157157 F extends RedisFunctions ,
158158 RESP extends RespVersions ,
159159 TYPE_MAPPING extends TypeMapping
160160> = {
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+ } ;
163164 } ;
164- } ;
165165
166166type WithScripts <
167167 S extends RedisScripts ,
168168 RESP extends RespVersions ,
169169 TYPE_MAPPING extends TypeMapping
170170> = {
171- [ P in keyof S ] : CommandSignature < S [ P ] , RESP , TYPE_MAPPING > ;
172- } ;
171+ [ P in keyof S ] : CommandSignature < S [ P ] , RESP , TYPE_MAPPING > ;
172+ } ;
173173
174174export type RedisClientExtensions <
175175 M extends RedisModules = { } ,
@@ -178,11 +178,11 @@ export type RedisClientExtensions<
178178 RESP extends RespVersions = 2 ,
179179 TYPE_MAPPING extends TypeMapping = { }
180180> = (
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+ ) ;
186186
187187export type RedisClientType <
188188 M extends RedisModules = { } ,
@@ -191,9 +191,9 @@ export type RedisClientType<
191191 RESP extends RespVersions = 2 ,
192192 TYPE_MAPPING extends TypeMapping = { }
193193> = (
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+ ) ;
197197
198198type ProxyClient = RedisClient < any , any , any , any , any > ;
199199
@@ -353,8 +353,8 @@ export default class RedisClient<
353353 #monitorCallback?: MonitorCallback < TYPE_MAPPING > ;
354354 private _self = this ;
355355 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
358358 // a topology change occured
359359 #dirtyWatch?: string ;
360360 #watchEpoch?: number ;
@@ -409,7 +409,7 @@ export default class RedisClient<
409409
410410 constructor ( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) {
411411 super ( ) ;
412-
412+ this . #validateOptions ( options )
413413 this . #options = this . #initiateOptions( options ) ;
414414 this . #queue = this . #initiateQueue( ) ;
415415 this . #socket = this . #initiateSocket( ) ;
@@ -425,6 +425,12 @@ export default class RedisClient<
425425 }
426426 }
427427
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+ }
428434 #initiateOptions( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > | undefined {
429435
430436 // Convert username/password to credentialsProvider if no credentialsProvider is already in place
@@ -482,7 +488,7 @@ export default class RedisClient<
482488 }
483489 }
484490
485- #subscribeForStreamingCredentials( cp : StreamingCredentialsProvider ) : Promise < [ BasicAuth , Disposable ] > {
491+ #subscribeForStreamingCredentials( cp : StreamingCredentialsProvider ) : Promise < [ BasicAuth , Disposable ] > {
486492 return cp . subscribe ( {
487493 onNext : credentials => {
488494 this . reAuthenticate ( credentials ) . catch ( error => {
@@ -517,7 +523,7 @@ export default class RedisClient<
517523
518524 if ( cp && cp . type === 'streaming-credentials-provider' ) {
519525
520- const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
526+ const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
521527 this . #credentialsSubscription = disposable ;
522528
523529 if ( credentials . password ) {
@@ -553,7 +559,7 @@ export default class RedisClient<
553559
554560 if ( cp && cp . type === 'streaming-credentials-provider' ) {
555561
556- const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
562+ const [ credentials , disposable ] = await this . #subscribeForStreamingCredentials( cp )
557563 this . #credentialsSubscription = disposable ;
558564
559565 if ( credentials . username || credentials . password ) {
@@ -1014,7 +1020,7 @@ export default class RedisClient<
10141020 * @internal
10151021 */
10161022 async _executePipeline (
1017- commands : Array < RedisMultiQueuedCommand > ,
1023+ commands : Array < RedisMultiQueuedCommand > ,
10181024 selectedDB ?: number
10191025 ) {
10201026 if ( ! this . _self . #socket. isOpen ) {
@@ -1065,8 +1071,8 @@ export default class RedisClient<
10651071 const typeMapping = this . _commandOptions ?. typeMapping ;
10661072 const chainId = Symbol ( 'MULTI Chain' ) ;
10671073 const promises = [
1068- this . _self . #queue. addCommand ( [ 'MULTI' ] , { chainId } ) ,
1069- ] ;
1074+ this . _self . #queue. addCommand ( [ 'MULTI' ] , { chainId } ) ,
1075+ ] ;
10701076
10711077 for ( const { args } of commands ) {
10721078 promises . push (
0 commit comments