import { RedisCacheAdapter } from "@daiso-tech/core/cache/redis-cache-adapter";
import { Serde } from "@daiso-tech/core/serde";
import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/super-json-serde-adapter"
import Redis from "ioredis";
const database = new Redis("YOUR_REDIS_CONNECTION_STRING");
const serde = new Serde(new SuperJsonSerdeAdapter());
const cacheAdapter = new RedisCacheAdapter({
database,
serde,
});
The add method adds a key with given value when key doesn't exists. Returns true when key doesn't exists otherwise false will be returned.
You can provide a ttl value. If null is passed, the item will not expire.
The increment method increments the given key with given value. Returns true if the key where incremented otherwise false will be returned.
If values is not defined then it will increment the key with 1.
An error will thrown if the key is not a number.
To utilize the
RedisCacheAdapter, you must install the"ioredis"package and supply aISerde<string>, with adapter likeSuperJsonSerdeAdapter.IMPORT_PATH:
"@daiso-tech/core/cache/redis-cache-adapter"