node-redisson
Version:
Distributed lock with Redis implementation for Node.js
36 lines (35 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Redisson = void 0;
const PubSubCommandExecutor_1 = require("./executor/PubSubCommandExecutor");
const StreamsCommandExecutor_1 = require("./executor/StreamsCommandExecutor");
const RedissonLock_1 = require("./locks/RedissonLock");
class Redisson {
constructor(config) {
const innerConfig = this.withDefaultConfig(config);
if (innerConfig.eventAdapter === 'streams') {
this.commandExecutor = new StreamsCommandExecutor_1.StreamsCommandExecutor(innerConfig);
}
else {
this.commandExecutor = new PubSubCommandExecutor_1.PubSubCommandExecutor(innerConfig);
}
}
withDefaultConfig(config) {
const { lockWatchdogTimeout = 30000n, eventAdapter = 'pubsub' } = config;
return {
lockWatchdogTimeout,
eventAdapter,
...config,
};
}
get redis() {
return this.commandExecutor.redis;
}
getLock(name, clientId) {
return new RedissonLock_1.RedissonLock(this.commandExecutor, name, clientId);
}
async quit() {
await Promise.allSettled([this.commandExecutor.redis.quit(), this.commandExecutor.subscribeRedis.quit()]);
}
}
exports.Redisson = Redisson;