redis/node-redis · error · Error

emitInvalidate is not supported (or necessary) when…

Error message

emitInvalidate is not supported (or necessary) when clientSideCache is enabled

What it means

clientSideCache already consumes invalidation push messages internally; enabling emitInvalidate at the same time would be redundant and ambiguous (two consumers for the same events). The two options are mutually exclusive and #validateOptions rejects the combination.

Solutions

  1. Use clientSideCache and let it handle invalidations, removing emitInvalidate.
  2. Or use emitInvalidate alone for custom handling and drop clientSideCache.

Example fix

// before
createClient({ clientSideCache: myCache, emitInvalidate: true });

// after
createClient({ clientSideCache: myCache });
Defensive patterns

Strategy: validation

Validate before calling

function validateCscVsEmit(options) {
  if (options?.clientSideCache && options?.emitInvalidate) {
    throw new Error('Enable only one of clientSideCache or emitInvalidate, not both');
  }
  return options;
}

Prevention

When it happens

Trigger: createClient({ clientSideCache: myCache, emitInvalidate: true }).

Common situations: Copy-pasting both options when migrating from a raw-invalidation setup to the cache abstraction; experimenting and forgetting to remove one.

Related errors


AI-assisted analysis of redis/node-redis@90fd0652bc (2026-08-11). Data as JSON: /api/errors/e235c13b1bb109ce. Report an issue: GitHub.

Appendix: source

Thrown at packages/client/lib/client/index.ts:800

          }
        } else {
          this.emit('invalidate', null);
        }
        return true
      });
    }
  }

  #validateOptions(options?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>) {
    const resp = options?.RESP ?? DEFAULT_RESP;
    if (options?.clientSideCache && resp !== 3) {
      throw new Error('Client Side Caching is only supported with RESP3');
    }
    if (options?.emitInvalidate && resp !== 3) {
      throw new Error('emitInvalidate is only supported with RESP3');
    }
    if (options?.clientSideCache && options?.emitInvalidate) {
      throw new Error('emitInvalidate is not supported (or necessary) when clientSideCache is enabled');
    }
    if (options?.maintNotifications && options?.maintNotifications !== 'disabled' && resp !== 3) {
      throw new Error('Graceful Maintenance is only supported with RESP3');
    }
  }

  #initiateOptions(options: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING> = {}): RedisClientOptions<M, F, S, RESP, TYPE_MAPPING> {

    // Convert username/password to credentialsProvider if no credentialsProvider is already in place
    if (!options.credentialsProvider && (options.username || options.password)) {

      options.credentialsProvider = {
        type: 'async-credentials-provider',
        credentials: async () => ({
          username: options.username,
          password: options.password
        })
      };

View on GitHub (pinned to 90fd0652bc)