import { MongodbSharedLockAdapter } from "@daiso-tech/core/shared-lock/mongodb-shared-lock-adapter";
import { MongoClient } from "mongodb";
const client = await MongoClient.connect("YOUR_MONGODB_CONNECTION_STRING");
const database = client.db("database");
const sharedLockAdapter = new MongodbSharedLockAdapter({
database
});
// You need initialize the adapter once before using it.
await sharedLockAdapter.init()
The acquireReader method acquires a slot only if the slot limit is not reached.
Returns true if the slot limit is not reached otherwise false is returned.
The refreshWriter method will upadte ttl of lock if it matches the owner and is expireable.
Returns false if the lock is unexpireable, the is expired, does not match the owner otherwise true is returned.
To utilize the
MongodbSharedLockAdapter, you must install the"mongodb"package.Note in order to use
MongodbSharedLockAdaptercorrectly, ensure you use a single, consistent database across all server instances.IMPORT_PATH:
"@daiso-tech/core/shared-lock/mongodb-shared-lock-adapter"