@@ -166,13 +166,31 @@ export async function getRedisInfo(
166166 return info ;
167167}
168168
169+ /**
170+ * Gets or creates a Redis client for queue operations.
171+ *
172+ * @param redisOpts - Redis connection options. Required if existingClient is not provided.
173+ * @param type - The type of queue ("bull" or "bullmq"), used for client caching key.
174+ * @param clusterNodes - Optional list of cluster node URIs for Redis Cluster.
175+ * @param existingClient - Optional pre-configured Redis/Cluster instance.
176+ * @returns A Redis or Cluster client.
177+ *
178+ * @remarks
179+ * When `existingClient` is provided, it is returned directly without caching.
180+ * This allows the caller to manage the client lifecycle independently.
181+ *
182+ * When `redisOpts` are provided (without existingClient), the created client
183+ * is cached internally using a checksum of the options. Subsequent calls with
184+ * the same options will reuse the cached client.
185+ */
169186export function getRedisClient (
170187 redisOpts : RedisOptions | undefined ,
171188 type : "bull" | "bullmq" ,
172189 clusterNodes ?: string [ ] ,
173190 existingClient ?: RedisConnection
174191) {
175- // If we have an existing client, use it directly
192+ // If an existing client is provided, return it directly.
193+ // We don't cache it since the caller owns its lifecycle.
176194 if ( existingClient ) {
177195 return existingClient ;
178196 }
@@ -181,7 +199,7 @@ export function getRedisClient(
181199 throw new Error ( "Redis options are required when no client is provided" ) ;
182200 }
183201
184- // Compute checksum for redisOpts
202+ // Compute checksum for redisOpts to use as cache key
185203 const checksumJson = JSON . stringify ( redisOpts ) ;
186204 const checksum = require ( "crypto" )
187205 . createHash ( "md5" )
0 commit comments