@cache-kit/cache-redis
v0.1.1
Published
Redis/Valkey CacheProvider for @cache-kit/cache, built against a structural client interface (works with ioredis, node-redis, or any compatible client).
Readme
@cache-kit/cache-redis
Redis/Valkey CacheProvider for
@cache-kit/cache, built
against a small structural client interface — works with ioredis,
node-redis, or any compatible client. No hard dependency on either.
npm install @cache-kit/cache @cache-kit/cache-redisWith the ioredis reference adapter
ioredis is an optional peer dependency — only needed if you use this
adapter. Importing the main package never requires it.
npm install ioredisimport Redis from 'ioredis';
import { Cache } from '@cache-kit/cache';
import { RedisProvider } from '@cache-kit/cache-redis';
import { createIoredisAdapter } from '@cache-kit/cache-redis/ioredis';
const redis = new Redis(process.env.REDIS_URL!);
const cache = new Cache({
provider: new RedisProvider({
type: 'redis', // use 'valkey' if you're on a Valkey server — same protocol, label only
client: createIoredisAdapter(redis),
keyPrefix: 'myapp',
}),
});Bring your own client instead by implementing RedisLikeClient (exported
from this package) — a handful of methods (get, set, setex, del,
sadd, smembers, mget, ...).
Cross-instance correctness
Tag and namespace invalidation (cache.invalidateTag(),
cache.invalidateNamespace()) work correctly across multiple app instances
sharing one Redis — not just within a single process. Every set() records
tag/namespace membership into Redis Sets, and this provider implements
search() so Cache can consult Redis directly rather than relying only on
its local in-process index. See the doc comment at the top of
redis-provider.ts for the full mechanism and its one known long-term
consideration (stale Set membership after natural TTL expiry).
Known limitations, by design:
cache.clear()(whole-cache wipe, no namespace) throws — a shared Redis instance may hold other apps' keys; usecache.invalidateNamespace(), or flush at the Redis client level yourself if you really mean "everything".cache.search()against a Redis-backed cache supportstagsandnamespacefilters only;prefix/owner/sourcefilters remain local-indexer-only (single-instance-correct).
License
MIT
