@fabric-es/fabric-cqrs
Version:
Hyperledger Fabric middleware for event sourcing and cqrs pattern
39 lines • 1.71 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.pipelineExec = void 0;
const util_1 = __importDefault(require("util"));
const debug_1 = __importDefault(require("debug"));
const utils_1 = require("../utils");
const debug = debug_1.default('queryHandler:createRedisRepository:pipelineExec');
const pipelineExec = async (client, action, pattern, keys) => {
const logger = utils_1.getLogger({ name: '[query-handler] pipelineExec.js', target: 'console' });
let pong;
try {
debug('ping: %s', action);
debug('ping: %pattern', pattern);
debug('redis-options, %O', client.redis.options);
pong = await client.redis.send_command('ping');
debug('ping redis-cli: %O', pong);
logger.info(`ping redis-cli: ${pong}`);
}
catch (err) {
logger.error(util_1.default.format('fail to ping Redis, %j', err));
}
if ((pong === null || pong === void 0 ? void 0 : pong.toLowerCase()) !== 'pong')
throw new Error('fail to PING redis');
const _keys = keys || (await client.redis.scan(0, 'MATCH', pattern, 'COUNT', 100000))[1];
if (!_keys)
throw new Error('keys not found');
const pipeline = client.redis.pipeline();
({
DELETE: () => _keys.forEach((key) => pipeline.del(key)),
HGETALL: () => _keys.forEach((key) => pipeline.hgetall(key)),
GET: () => _keys.forEach((key) => pipeline.get(key)),
}[action]());
return pipeline.exec();
};
exports.pipelineExec = pipelineExec;
//# sourceMappingURL=pipelineExec.js.map