feat: add default retry strategy for redis (#10880)

Fixes: FRMW-2861
This commit is contained in:
Harminder Virk
2025-01-09 05:26:08 +00:00
committed by GitHub
parent bd73716bb6
commit 67782350a9
3 changed files with 42 additions and 1 deletions
@@ -142,6 +142,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
@@ -298,6 +301,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
@@ -462,6 +468,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
@@ -627,6 +636,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
@@ -780,6 +792,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
@@ -933,6 +948,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
@@ -74,7 +74,8 @@ type Config = Partial<
* to override configuration as needed.
*/
export function defineConfig(config: Config = {}): ConfigModule {
const { http, ...restOfProjectConfig } = config.projectConfig || {}
const { http, redisOptions, ...restOfProjectConfig } =
config.projectConfig || {}
/**
* The defaults to use for the project config. They are shallow merged
@@ -93,6 +94,23 @@ export function defineConfig(config: Config = {}): ConfigModule {
},
...http,
},
redisOptions: {
retryStrategy(retries) {
/**
* Exponentially increase delay with every retry
* attempt. Max to 4s
*/
const delay = Math.min(Math.pow(2, retries) * 50, 4000)
/**
* Add a random jitter to not choke the server when multiple
* clients are retrying at the same time
*/
const jitter = Math.floor(Math.random() * 200)
return delay + jitter
},
...redisOptions,
},
...restOfProjectConfig,
}