import { RedisLockAdapter, SuperJsonSerde } from "@daiso-tech/core/lock/implementations/adapters";
import Redis from "ioredis";
const database = new Redis("YOUR_REDIS_CONNECTION_STRING");
const serde = new SuperJsonSerde();
const lockAdapter = new RedisLockAdapter({
database,
serde,
rootGroup: "@global"
});
The acquire method acquires a lock only if the lock is not already acquired. Returns true if not already acquired othewise false is returned.
The refresh method will upadte ttl of lock if it matches the given key and matches the given owner. Returns true if the update occured otherwise false is returned.
The withGroup method returns a new IDatabaseLockAdapter instance that groups locks together. Only locks in the same group will be acquired and released, leaving locks outside the group unaffected.
To utilize the RedisLockAdapter, you must install the "ioredis" package.
Note in order to use RedisLockAdapter correctly, ensure you use a single, consistent database across all server instances.
IMPORT_PATH:
"@daiso-tech/core/lock/implementations/adapters"