redis-smq
Version:
A simple high-performance Redis message queue for Node.js.
56 lines • 2.14 kB
JavaScript
import { CallbackEmptyReplyError } from 'redis-smq-common';
import { redisKeys } from '../../../common/redis-keys/redis-keys.js';
import { QueueMessagesStorage } from './queue-messages-storage.js';
export class QueueMessagesStorageSet extends QueueMessagesStorage {
count(queue, redisKey, cb) {
const keys = redisKeys.getQueueKeys(queue.queueParams, queue.groupId);
this.redisClient.getSetInstance((err, client) => {
if (err)
cb(err);
else if (!client)
cb(new CallbackEmptyReplyError());
else {
client.scard(keys[redisKey], (err, reply) => {
if (err)
cb(err);
else if (!reply)
cb(new CallbackEmptyReplyError());
else
cb(null, reply);
});
}
});
}
fetchItems(queue, redisKey, offset, limit, cb) {
const keys = redisKeys.getQueueKeys(queue.queueParams, queue.groupId);
this.redisClient.getSetInstance((err, client) => {
if (err)
cb(err);
else if (!client)
cb(new CallbackEmptyReplyError());
else {
client.sscan(keys[redisKey], offset.toString(), { COUNT: limit }, (err, reply) => {
if (err)
cb(err);
else if (!reply)
cb(new 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 CallbackEmptyReplyError());
else {
const keys = redisKeys.getQueueKeys(queue.queueParams, queue.groupId);
client.sscanAll(keys[redisKey], { COUNT: 100 }, cb);
}
});
}
}
//# sourceMappingURL=queue-messages-storage-set.js.map