| 50 | } |
| 51 | |
| 52 | async set(key: string, value: unknown, ttlSeconds?: number): Promise<void> { |
| 53 | try { |
| 54 | const serializedValue = this.stringifyValue(value); |
| 55 | const redisKey = this.getKey(key); |
| 56 | const ttl = ttlSeconds ?? this.defaultTTL; |
| 57 | |
| 58 | if (ttl > 0) { |
| 59 | await this.redis.setEx(redisKey, ttl, serializedValue); |
| 60 | } else { |
| 61 | await this.redis.set(redisKey, serializedValue); |
| 62 | } |
| 63 | } catch (error) { |
| 64 | console.error( |
| 65 | `Redis set error for ${this.prefix} cache, key "${key}":`, |
| 66 | error, |
| 67 | ); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | async delete(key: string): Promise<void> { |
| 72 | try { |