n8n
Version:
n8n Workflow Automation Tool
62 lines • 2.84 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisServicePubSubPublisher = void 0;
const typedi_1 = require("typedi");
const RedisConstants_1 = require("./RedisConstants");
const RedisServiceBaseClasses_1 = require("./RedisServiceBaseClasses");
let RedisServicePubSubPublisher = class RedisServicePubSubPublisher extends RedisServiceBaseClasses_1.RedisServiceBaseSender {
async init() {
await super.init('publisher');
}
async publish(channel, message) {
var _a;
if (!this.redisClient) {
await this.init();
}
await ((_a = this.redisClient) === null || _a === void 0 ? void 0 : _a.publish(channel, message));
}
async publishToCommandChannel(message) {
const messageWithSenderId = message;
messageWithSenderId.senderId = this.senderId;
await this.publish(RedisConstants_1.COMMAND_REDIS_CHANNEL, JSON.stringify(messageWithSenderId));
}
async publishToWorkerChannel(message) {
await this.publish(RedisConstants_1.WORKER_RESPONSE_REDIS_CHANNEL, JSON.stringify(message));
}
async setIfNotExists(key, value) {
var _a;
if (!this.redisClient)
await this.init();
const success = await ((_a = this.redisClient) === null || _a === void 0 ? void 0 : _a.setnx(key, value));
return !!success;
}
async setExpiration(key, ttl) {
var _a;
if (!this.redisClient)
await this.init();
await ((_a = this.redisClient) === null || _a === void 0 ? void 0 : _a.expire(key, ttl));
}
async get(key) {
var _a;
if (!this.redisClient)
await this.init();
return await ((_a = this.redisClient) === null || _a === void 0 ? void 0 : _a.get(key));
}
async clear(key) {
var _a;
if (!this.redisClient)
await this.init();
await ((_a = this.redisClient) === null || _a === void 0 ? void 0 : _a.del(key));
}
};
exports.RedisServicePubSubPublisher = RedisServicePubSubPublisher;
exports.RedisServicePubSubPublisher = RedisServicePubSubPublisher = __decorate([
(0, typedi_1.Service)()
], RedisServicePubSubPublisher);
//# sourceMappingURL=RedisServicePubSubPublisher.js.map
;