* Wraps Redis operations with connection check and timeout to prevent hanging
(operation: Promise<T>, timeoutMs = 1000)
| 24 | * Wraps Redis operations with connection check and timeout to prevent hanging |
| 25 | */ |
| 26 | private async withTimeout<T>(operation: Promise<T>, timeoutMs = 1000): Promise<T> { |
| 27 | return Promise.race([ |
| 28 | operation, |
| 29 | new Promise<T>((_, reject) => { |
| 30 | setTimeout(() => { |
| 31 | reject(new CacheErrorClass(ErrorCode.RedisOperationError, "Cache operation timeout")); |
| 32 | }, timeoutMs); |
| 33 | }), |
| 34 | ]); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Get the underlying Redis client for advanced operations (e.g., Lua scripts) |