1- import { commandOptions , createClient } from 'redis' ;
1+ import { commandOptions , createClient , RedisClientOptions } from 'redis' ;
22import { SyncedMap } from './SyncedMap' ;
33import { DeduplicatedRequestHandler } from './DeduplicatedRequestHandler' ;
44import { debug } from './utils/debug' ;
@@ -60,6 +60,14 @@ export type CreateRedisStringsHandlerOptions = {
6060 * @default Production: staleAge * 2, Other: staleAge * 1.2
6161 */
6262 estimateExpireAge ?: ( staleAge : number ) => number ;
63+ /** Additional Redis client socket options
64+ * @example { tls: true, rejectUnauthorized: false }
65+ */
66+ socketOptions ?: RedisClientOptions [ 'socket' ] ;
67+ /** Additional Redis client options to be passed directly to createClient
68+ * @example { username: 'user', password: 'pass' }
69+ */
70+ clientOptions ?: Omit < RedisClientOptions , 'url' | 'database' | 'socket' > ;
6371} ;
6472
6573// Identifier prefix used by Next.js to mark automatically generated cache tags
@@ -113,6 +121,8 @@ export default class RedisStringsHandler {
113121 defaultStaleAge = 60 * 60 * 24 * 14 ,
114122 estimateExpireAge = ( staleAge ) =>
115123 process . env . VERCEL_ENV === 'production' ? staleAge * 2 : staleAge * 1.2 ,
124+ socketOptions,
125+ clientOptions,
116126 } : CreateRedisStringsHandlerOptions ) {
117127 this . keyPrefix = keyPrefix ;
118128 this . timeoutMs = timeoutMs ;
@@ -122,9 +132,12 @@ export default class RedisStringsHandler {
122132 this . estimateExpireAge = estimateExpireAge ;
123133
124134 try {
135+ // Create Redis client with properly typed configuration
125136 this . client = createClient ( {
126- ...( database !== 0 ? { database } : { } ) ,
127137 url : redisUrl ,
138+ ...( database !== 0 ? { database } : { } ) ,
139+ ...( socketOptions ? { socket : socketOptions } : { } ) ,
140+ ...( clientOptions || { } ) ,
128141 } ) ;
129142
130143 this . client . on ( 'error' , ( error ) => {
0 commit comments