Skip to content

Commit 01eb844

Browse files
authored
Merge pull request #28 from trieb-work/feat-skip-keyspace-check
feat: option for disable keyspace config check for cloud envs
2 parents 42472f4 + 0b8878d commit 01eb844

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ REDISHOST and REDISPORT environment variables are required.
4848
VERCEL_URL, VERCEL_ENV are optional. VERCEL_URL is used to create a key prefix for the redis keys. VERCEL_ENV is used to determine the database to use. Only VERCEL_ENV=production will show up in DB 0 (redis default db). All other values of VERCEL_ENV will use DB 1, use `redis-cli -n 1` to connect to different DB 1. This is another protection feature to avoid that different environments (e.g. staging and production) will overwrite each other.
4949
Furthermore there exists the DEBUG_CACHE_HANDLER environment variable to enable debug logging of the caching handler once it is set to true.
5050

51+
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).
52+
5153
### Option A: minimum implementation with default options
5254

5355
extend `next.config.js` with:

src/SyncedMap.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,28 @@ export class SyncedMap<V> {
206206
});
207207

208208
// Check if keyspace event configuration is set correctly
209-
const keyspaceEventConfig = (
210-
await this.subscriberClient.configGet('notify-keyspace-events')
211-
)?.['notify-keyspace-events'];
212-
if (!keyspaceEventConfig.includes('E')) {
213-
throw new Error(
214-
"Keyspace event configuration has to include 'E' for Keyevent events, published with __keyevent@<db>__ prefix. We recommend to set it to 'Exe' like so `redis-cli -h localhost config set notify-keyspace-events Exe`",
215-
);
216-
}
217209
if (
218-
!keyspaceEventConfig.includes('A') &&
219-
!(
220-
keyspaceEventConfig.includes('x') && keyspaceEventConfig.includes('e')
221-
)
210+
(process.env.SKIP_KEYSPACE_CONFIG_CHECK || '').toUpperCase() !== 'TRUE'
222211
) {
223-
throw new Error(
224-
"Keyspace event configuration has to include 'A' or 'x' and 'e' for expired and evicted events. We recommend to set it to 'Exe' like so `redis-cli -h localhost config set notify-keyspace-events Exe`",
225-
);
212+
const keyspaceEventConfig = (
213+
await this.subscriberClient.configGet('notify-keyspace-events')
214+
)?.['notify-keyspace-events'];
215+
if (!keyspaceEventConfig.includes('E')) {
216+
throw new Error(
217+
"Keyspace event configuration has to include 'E' for Keyevent events, published with __keyevent@<db>__ prefix. We recommend to set it to 'Exe' like so `redis-cli -h localhost config set notify-keyspace-events Exe`",
218+
);
219+
}
220+
if (
221+
!keyspaceEventConfig.includes('A') &&
222+
!(
223+
keyspaceEventConfig.includes('x') &&
224+
keyspaceEventConfig.includes('e')
225+
)
226+
) {
227+
throw new Error(
228+
"Keyspace event configuration has to include 'A' or 'x' and 'e' for expired and evicted events. We recommend to set it to 'Exe' like so `redis-cli -h localhost config set notify-keyspace-events Exe`",
229+
);
230+
}
226231
}
227232

228233
await Promise.all([

0 commit comments

Comments
 (0)