| 28 | > = RedisClientType<M, F, S, 3, TypeMapping>; |
| 29 | |
| 30 | export const createRedisClient = < |
| 31 | M extends RedisModules, |
| 32 | F extends RedisFunctions, |
| 33 | S extends RedisScripts, |
| 34 | >( |
| 35 | options: ClientOptions<M, F, S>, |
| 36 | ): RedisClientType<M, F, S, 3, TypeMapping> => { |
| 37 | const { logger, ...rest } = options; |
| 38 | |
| 39 | return createClient({ ...rest, RESP: 3 }) |
| 40 | .on("connect", () => { |
| 41 | logger.debug("Redis client is connecting"); |
| 42 | }) |
| 43 | .on("reconnecting", () => logger.debug(`Redis reconnecting...`)) |
| 44 | .on("ready", () => { |
| 45 | logger.debug("Redis client is connected and ready."); |
| 46 | }) |
| 47 | .on("end", () => { |
| 48 | logger.debug("Redis connection has been disconnected by client."); |
| 49 | }) |
| 50 | .on("error", (error) => { |
| 51 | logger.error({ |
| 52 | message: "Redis connection lost", |
| 53 | errorMessage: `${(error as Error).name}: ${(error as Error).message}`, |
| 54 | }); |
| 55 | }); |
| 56 | }; |