@cache-utils/adapter-redis
v0.0.2
Published
Redis-backed CacheAdapter for @cache-utils/core, built on ioredis.
Maintainers
Readme
@cache-utils/adapter-redis
Redis-backed CacheAdapter for @cache-utils/core, built on ioredis.
Supports get/set/setIfNotExists/del plus the optional batch and scan
methods (mget, mset, scanByPrefix) CacheManager can use when the
adapter provides them.
Install
npm install @cache-utils/adapter-redis @cache-utils/core ioredisUsage
import Redis from "ioredis";
import { CacheManager } from "@cache-utils/core";
import { RedisAdapter } from "@cache-utils/adapter-redis";
const client = new Redis(process.env.REDIS_URL);
const cache = new CacheManager(new RedisAdapter(client));
await cache.set("user:1", { name: "Ada" }, 60);
const user = await cache.get<{ name: string }>("user:1");
// distributed locks use Redis SET NX under the hood
await cache.withLock("job:daily-report", 30, async () => {
await runDailyReport();
});You own the ioredis client (cluster, sentinel, TLS, etc. all configure
through it as normal) — RedisAdapter just wraps it to satisfy the
CacheAdapter interface.
License
MIT
