Skip to content

Commit cd2aece

Browse files
committed
redis quit
1 parent 9cc4311 commit cd2aece

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/service/cache/service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { KVNamespace } from '@cloudflare/workers-types'
22
import { createClient } from 'redis'
33
import type { RedisClientType } from 'redis'
44
import type { Environment } from '#/types/index'
5+
import { close } from 'fs'
56

67
export interface ICacheService {
78
get(key: string): Promise<{} | null>
@@ -34,11 +35,16 @@ export class CacheService implements ICacheService {
3435
this.#connecting = true
3536

3637
const client: RedisClientType = createClient({
37-
url: this.#env.REDIS_URL
38+
url: this.#env.REDIS_URL,
39+
socket: {
40+
connectTimeout: 10000
41+
}
3842
})
3943

4044
client.on('error', (err: Error) => {
4145
console.error(`Redis Error: ${err.message}`)
46+
client.quit()
47+
this.#client = null
4248
})
4349

4450
try {
@@ -72,6 +78,7 @@ export class CacheService implements ICacheService {
7278
if (this.#cacheType === 'redis') {
7379
const client = await this.getRedisClient()
7480
const result = await client.get(key)
81+
client.quit()
7582
return result ? (JSON.parse(result as string) as {}) : null
7683
}
7784
return this.#env.EFP_DATA_CACHE.get(key, 'json')
@@ -85,6 +92,7 @@ export class CacheService implements ICacheService {
8592
} else {
8693
await client.set(key, value, { EX: ttl } as any)
8794
}
95+
client.quit()
8896
} else if (ttl === 0) {
8997
await this.#env.EFP_DATA_CACHE.put(key, value, {})
9098
} else {

0 commit comments

Comments
 (0)