Skip to content

Commit dd591da

Browse files
committed
feat: improve error handling
1 parent 3c646a0 commit dd591da

File tree

3 files changed

+550
-375
lines changed

3 files changed

+550
-375
lines changed

README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ Furthermore there exists the DEBUG_CACHE_HANDLER environment variable to enable
5050

5151
There exists also the SKIP_KEYSPACE_CONFIG_CHECK environment variable to skip the check for the keyspace configuration. This is useful if you are using redis in a cloud environment that forbids access to config commands. If you set SKIP_KEYSPACE_CONFIG_CHECK=true the check will be skipped and the keyspace configuration will be assumed to be correct (e.g. notify-keyspace-events Exe).
5252

53+
KILL_CONTAINER_ON_ERROR_THRESHOLD: Optional environment variable that defines how many Redis client errors should occur before the process exits with code 1. This is useful in container environments like Kubernetes where you want the container to restart if Redis connectivity issues persist. Set to 0 (default) to disable this feature. For example, setting KILL_CONTAINER_ON_ERROR_THRESHOLD=10 will exit the process after 10 Redis client errors, allowing the container orchestrator to restart the container.
54+
55+
REDIS_COMMAND_TIMEOUT_MS: Optional environment variable that sets the timeout in milliseconds for Redis commands. If not set, defaults to 5000ms (5 seconds). The value is parsed as an integer, and if parsing fails, falls back to the 5000ms default.
56+
5357
### Option A: minimum implementation with default options
5458

5559
extend `next.config.js` with:
@@ -119,21 +123,22 @@ A working example of above can be found in the `test/integration/next-app-custom
119123

120124
## Available Options
121125

122-
| Option | Description | Default Value |
123-
| ---------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
124-
| redisUrl | Redis connection url | `process.env.REDIS_URL? process.env.REDIS_URL : process.env.REDISHOST ? redis://${process.env.REDISHOST}:${process.env.REDISPORT} : 'redis://localhost:6379'` |
125-
| database | Redis database number to use. Uses DB 0 for production, DB 1 otherwise | `process.env.VERCEL_ENV === 'production' ? 0 : 1` |
126-
| keyPrefix | Prefix added to all Redis keys | `process.env.VERCEL_URL \|\| 'UNDEFINED_URL_'` |
127-
| sharedTagsKey | Key used to store shared tags hash map in Redis | `'__sharedTags__'` |
128-
| timeoutMs | Timeout in milliseconds for Redis operations | `5000` |
129-
| revalidateTagQuerySize | Number of entries to query in one batch during full sync of shared tags hash map | `250` |
130-
| avgResyncIntervalMs | Average interval in milliseconds between tag map full re-syncs | `3600000` (1 hour) |
131-
| redisGetDeduplication | Enable deduplication of Redis get requests via internal in-memory cache. | `true` |
132-
| inMemoryCachingTime | Time in milliseconds to cache Redis get results in memory. Set this to 0 to disable in-memory caching completely. | `10000` |
133-
| defaultStaleAge | Default stale age in seconds for cached items | `1209600` (14 days) |
134-
| estimateExpireAge | Function to calculate expire age (redis TTL value) from stale age | Production: `staleAge * 2`<br> Other: `staleAge * 1.2` |
135-
| socketOptions | Redis client socket options for TLS/SSL configuration (e.g., `{ tls: true, rejectUnauthorized: false }`) | `undefined` |
136-
| clientOptions | Additional Redis client options (e.g., username, password) | `undefined` |
126+
| Option | Description | Default Value |
127+
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
128+
| redisUrl | Redis connection url | `process.env.REDIS_URL? process.env.REDIS_URL : process.env.REDISHOST ? redis://${process.env.REDISHOST}:${process.env.REDISPORT} : 'redis://localhost:6379'` |
129+
| database | Redis database number to use. Uses DB 0 for production, DB 1 otherwise | `process.env.VERCEL_ENV === 'production' ? 0 : 1` |
130+
| keyPrefix | Prefix added to all Redis keys | `process.env.VERCEL_URL \|\| 'UNDEFINED_URL_'` |
131+
| sharedTagsKey | Key used to store shared tags hash map in Redis | `'__sharedTags__'` |
132+
| timeoutMs | Timeout in milliseconds for Redis operations | `Number.parseInt(process.env.REDIS_COMMAND_TIMEOUT_MS) ?? 5_000 : 5_000` |
133+
| revalidateTagQuerySize | Number of entries to query in one batch during full sync of shared tags hash map | `250` |
134+
| avgResyncIntervalMs | Average interval in milliseconds between tag map full re-syncs | `3600000` (1 hour) |
135+
| redisGetDeduplication | Enable deduplication of Redis get requests via internal in-memory cache. | `true` |
136+
| inMemoryCachingTime | Time in milliseconds to cache Redis get results in memory. Set this to 0 to disable in-memory caching completely. | `10000` |
137+
| defaultStaleAge | Default stale age in seconds for cached items | `1209600` (14 days) |
138+
| estimateExpireAge | Function to calculate expire age (redis TTL value) from stale age | Production: `staleAge * 2`<br> Other: `staleAge * 1.2` |
139+
| socketOptions | Redis client socket options for TLS/SSL configuration (e.g., `{ tls: true, rejectUnauthorized: false }`) | `{ connectTimeout: timeoutMs }` |
140+
| clientOptions | Additional Redis client options (e.g., username, password) | `undefined` |
141+
| killContainerOnErrorThreshold | Number of consecutive errors before the container is killed. Set to 0 to disable. | `Number.parseInt(process.env.KILL_CONTAINER_ON_ERROR_THRESHOLD) ?? 0 : 0` |
137142

138143
## TLS Configuration
139144

0 commit comments

Comments
 (0)