redis-smq
Version:
A simple high-performance Redis message queue for Node.js.
40 lines • 1.6 kB
JavaScript
import { async } from 'redis-smq-common';
import { redisKeys } from '../../../common/redis-keys/redis-keys.js';
import { MessageMessageNotFoundError } from '../errors/index.js';
import { EMessageProperty } from '../types/index.js';
import { _fromMessage } from './_from-message.js';
export function _getMessage(redisClient, messageId, cb) {
const { keyMessage } = redisKeys.getMessageKeys(messageId);
redisClient.hgetall(keyMessage, (err, reply) => {
if (err)
cb(err);
else if (!reply || !Object.keys(reply).length)
cb(new MessageMessageNotFoundError());
else
cb(null, _fromMessage(reply[EMessageProperty.MESSAGE], Number(reply[EMessageProperty.STATUS]), reply[EMessageProperty.STATE]));
});
}
export function _getMessages(redisClient, messageIds, cb) {
const messages = [];
async.each(messageIds, (id, index, done) => {
const { keyMessage } = redisKeys.getMessageKeys(id);
redisClient.hgetall(keyMessage, (err, reply) => {
if (err)
done(err);
else if (!reply || !Object.keys(reply).length) {
done(new MessageMessageNotFoundError());
}
else {
const msg = _fromMessage(reply[EMessageProperty.MESSAGE], Number(reply[EMessageProperty.STATUS]), reply[EMessageProperty.STATE]);
messages.push(msg);
done();
}
});
}, (err) => {
if (err)
cb(err);
else
cb(null, messages);
});
}
//# sourceMappingURL=_get-message.js.map