UNPKG

redis-smq

Version:

A simple high-performance Redis message queue for Node.js.

60 lines 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.QueueMessagesStorageSet = void 0; const redis_smq_common_1 = require("redis-smq-common"); const redis_keys_js_1 = require("../../../common/redis-keys/redis-keys.js"); const queue_messages_storage_js_1 = require("./queue-messages-storage.js"); class QueueMessagesStorageSet extends queue_messages_storage_js_1.QueueMessagesStorage { count(queue, redisKey, cb) { const keys = redis_keys_js_1.redisKeys.getQueueKeys(queue.queueParams, queue.groupId); this.redisClient.getSetInstance((err, client) => { if (err) cb(err); else if (!client) cb(new redis_smq_common_1.CallbackEmptyReplyError()); else { client.scard(keys[redisKey], (err, reply) => { if (err) cb(err); else if (!reply) cb(new redis_smq_common_1.CallbackEmptyReplyError()); else cb(null, reply); }); } }); } fetchItems(queue, redisKey, offset, limit, cb) { const keys = redis_keys_js_1.redisKeys.getQueueKeys(queue.queueParams, queue.groupId); this.redisClient.getSetInstance((err, client) => { if (err) cb(err); else if (!client) cb(new redis_smq_common_1.CallbackEmptyReplyError()); else { client.sscan(keys[redisKey], offset.toString(), { COUNT: limit }, (err, reply) => { if (err) cb(err); else if (!reply) cb(new redis_smq_common_1.CallbackEmptyReplyError()); else cb(null, reply ? reply.items : []); }); } }); } fetchAllItems(queue, redisKey, cb) { this.redisClient.getSetInstance((err, client) => { if (err) cb(err); else if (!client) cb(new redis_smq_common_1.CallbackEmptyReplyError()); else { const keys = redis_keys_js_1.redisKeys.getQueueKeys(queue.queueParams, queue.groupId); client.sscanAll(keys[redisKey], { COUNT: 100 }, cb); } }); } } exports.QueueMessagesStorageSet = QueueMessagesStorageSet; //# sourceMappingURL=queue-messages-storage-set.js.map