{"id":"e235c13b1bb109ce","repo":"redis/node-redis","slug":"emitinvalidate-is-not-supported-or-necessary-whe","errorCode":null,"errorMessage":"emitInvalidate is not supported (or necessary) when clientSideCache is enabled","messagePattern":"emitInvalidate is not supported \\(or necessary\\) when clientSideCache is enabled","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/client/lib/client/index.ts","lineNumber":800,"sourceCode":"          }\n        } else {\n          this.emit('invalidate', null);\n        }\n        return true\n      });\n    }\n  }\n\n  #validateOptions(options?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>) {\n    const resp = options?.RESP ?? DEFAULT_RESP;\n    if (options?.clientSideCache && resp !== 3) {\n      throw new Error('Client Side Caching is only supported with RESP3');\n    }\n    if (options?.emitInvalidate && resp !== 3) {\n      throw new Error('emitInvalidate is only supported with RESP3');\n    }\n    if (options?.clientSideCache && options?.emitInvalidate) {\n      throw new Error('emitInvalidate is not supported (or necessary) when clientSideCache is enabled');\n    }\n    if (options?.maintNotifications && options?.maintNotifications !== 'disabled' && resp !== 3) {\n      throw new Error('Graceful Maintenance is only supported with RESP3');\n    }\n  }\n\n  #initiateOptions(options: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING> = {}): RedisClientOptions<M, F, S, RESP, TYPE_MAPPING> {\n\n    // Convert username/password to credentialsProvider if no credentialsProvider is already in place\n    if (!options.credentialsProvider && (options.username || options.password)) {\n\n      options.credentialsProvider = {\n        type: 'async-credentials-provider',\n        credentials: async () => ({\n          username: options.username,\n          password: options.password\n        })\n      };","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/redis/node-redis/blob/bb5beb56578573910e2ee8f39681edc214c41398/packages/client/lib/client/index.ts#L782-L818","documentation":"#validateOptions rejects setting both `clientSideCache` and `emitInvalidate` at once. When client-side caching is enabled, the cache provider already consumes 'invalidate' push messages internally to evict stale entries, so a separate emitInvalidate handler is redundant and would double-process the same pushes (or conflict over the push stream). The client tells you emitInvalidate is unnecessary in that mode.","triggerScenarios":"`createClient({ clientSideCache: new BasicClientSideCache(), emitInvalidate: true })`; layered config turning both features on.","commonSituations":"Enabling the cache and also wanting invalidate events 'just in case'; merging two config fragments each enabling one of the features; upgrading from emitInvalidate to the full cache without removing the old flag.","solutions":["If you use clientSideCache, remove emitInvalidate — the cache already handles invalidation (and emits its own 'invalidate' event on the provider).","If you only want raw invalidate events without caching, drop clientSideCache and keep emitInvalidate.","Centralize config so the two flags are mutually exclusive."],"exampleFix":"// before\ncreateClient({ clientSideCache: new BasicClientSideCache(), emitInvalidate: true });\n\n// after\ncreateClient({ clientSideCache: new BasicClientSideCache() });","handlingStrategy":"validation","validationCode":"function makeClient(opts) {\n  if (opts.clientSideCache && opts.emitInvalidate) {\n    throw new TypeError('Do not set emitInvalidate when clientSideCache is enabled');\n  }\n  return createClient(opts);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one: either clientSideCache (handles invalidation internally) or emitInvalidate (raw events), not both.","When upgrading from emitInvalidate to the full cache, remove the emitInvalidate flag."],"tags":["config","client-side-caching","validation"],"analyzedSha":"bb5beb56578573910e2ee8f39681edc214c41398","analyzedAt":"2026-08-03T19:09:15.686Z","schemaVersion":2}