Skip to content

Commit

Permalink
fix: unlimited retries with double time
Browse files Browse the repository at this point in the history
  • Loading branch information
jpvargasdev committed Sep 25, 2024
1 parent 3fb8b8d commit f145e39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-lions-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sebspark/promise-cache": patch
---

Remove max 5 tries
17 changes: 8 additions & 9 deletions packages/promise-cache/src/persistor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ export class Persistor {
...this.redis,
socket: {
reconnectStrategy: (retries, cause) => {
if (retries === 5) {
console.error('Error reconnecting... ', cause)
return false
}
return retries * 1000
console.error(cause)
return 1000 * 2 ** retries
},
},
})
Expand Down Expand Up @@ -131,8 +128,9 @@ export class Persistor {
key: string,
{ value, timestamp, ttl }: SetParams<T>
): Promise<void> {
if (!this.client) {
throw new Error('Client not connected')
if (!this.client || !this.client.isReady) {
console.error('Client not ready')
return
}
try {
const serializedData = JSON.stringify({ value, ttl, timestamp })
Expand All @@ -144,8 +142,9 @@ export class Persistor {
}

public async delete(key: string): Promise<void> {
if (!this.client) {
throw new Error('Client not connected')
if (!this.client || !this.client.isReady) {
console.error('Client not ready')
return
}
try {
await this.client.del(key)
Expand Down

0 comments on commit f145e39

Please sign in to comment.