@@ -13,6 +13,16 @@ export type CacheEntry = {
1313 tags : string [ ] ;
1414} ;
1515
16+ export function redisErrorHandler < T extends Promise < unknown > > (
17+ debugInfo : string ,
18+ redisCommandResult : T ,
19+ ) : T {
20+ return redisCommandResult . catch ( ( error ) => {
21+ console . error ( 'Redis command error' , debugInfo , error ) ;
22+ throw error ;
23+ } ) as T ;
24+ }
25+
1626export type CreateRedisStringsHandlerOptions = {
1727 /** Redis redisUrl to use.
1828 * @default process.env.REDIS_URL? process.env.REDIS_URL : process.env.REDISHOST
@@ -352,9 +362,19 @@ export default class RedisStringsHandler {
352362 const clientGet = this . redisGetDeduplication
353363 ? this . deduplicatedRedisGet ( key )
354364 : this . redisGet ;
355- const serializedCacheEntry = await clientGet (
356- getTimeoutRedisCommandOptions ( this . timeoutMs ) ,
357- this . keyPrefix + key ,
365+ const serializedCacheEntry = await redisErrorHandler (
366+ 'RedisStringsHandler.get(), operation: get' +
367+ ( this . redisGetDeduplication ? 'deduplicated' : '' ) +
368+ this . timeoutMs +
369+ 'ms' +
370+ ' ' +
371+ this . keyPrefix +
372+ ' ' +
373+ key ,
374+ clientGet (
375+ getTimeoutRedisCommandOptions ( this . timeoutMs ) ,
376+ this . keyPrefix + key ,
377+ ) ,
358378 ) ;
359379
360380 debug (
@@ -595,13 +615,17 @@ export default class RedisStringsHandler {
595615
596616 // Setting the cache entry in redis
597617 const options = getTimeoutRedisCommandOptions ( this . timeoutMs ) ;
598- const setOperation : Promise < string | null > = this . client . set (
599- options ,
600- this . keyPrefix + key ,
601- serializedCacheEntry ,
602- {
618+ const setOperation : Promise < string | null > = redisErrorHandler (
619+ 'RedisStringsHandler.set(), operation: set' +
620+ this . timeoutMs +
621+ 'ms' +
622+ ' ' +
623+ this . keyPrefix +
624+ ' ' +
625+ key ,
626+ this . client . set ( options , this . keyPrefix + key , serializedCacheEntry , {
603627 EX : expireAt ,
604- } ,
628+ } ) ,
605629 ) ;
606630
607631 debug (
@@ -725,7 +749,16 @@ export default class RedisStringsHandler {
725749 const redisKeys = Array . from ( keysToDelete ) ;
726750 const fullRedisKeys = redisKeys . map ( ( key ) => this . keyPrefix + key ) ;
727751 const options = getTimeoutRedisCommandOptions ( this . timeoutMs ) ;
728- const deleteKeysOperation = this . client . unlink ( options , fullRedisKeys ) ;
752+ const deleteKeysOperation = redisErrorHandler (
753+ 'RedisStringsHandler.revalidateTag(), operation: unlink' +
754+ this . timeoutMs +
755+ 'ms' +
756+ ' ' +
757+ this . keyPrefix +
758+ ' ' +
759+ fullRedisKeys ,
760+ this . client . unlink ( options , fullRedisKeys ) ,
761+ ) ;
729762
730763 // also delete entries from in-memory deduplication cache if they get revalidated
731764 if ( this . redisGetDeduplication && this . inMemoryCachingTime > 0 ) {
0 commit comments