(options = {})
| 5 | const EventEmitter = require("events").EventEmitter; |
| 6 | class RedisSMQ extends EventEmitter { |
| 7 | constructor(options = {}) { |
| 8 | super(options); |
| 9 | this.asyncify = (methodKey) => { |
| 10 | const asyncMethodKey = methodKey + "Async"; |
| 11 | this[asyncMethodKey] = (...args) => { |
| 12 | return new Promise((resolve, reject) => { |
| 13 | this[methodKey](...args, (err, result) => { |
| 14 | if (err) { |
| 15 | reject(err); |
| 16 | return; |
| 17 | } |
| 18 | resolve(result); |
| 19 | }); |
| 20 | }); |
| 21 | }; |
| 22 | }; |
| 23 | this.quit = (cb) => { |
| 24 | if (cb === undefined) { |
| 25 | cb = () => { }; |
| 26 | } |
| 27 | this.redis.quit(cb); |
| 28 | }; |
| 29 | this._getQueue = (qname, uid, cb) => { |
| 30 | const mc = [ |
| 31 | ["hmget", `${this.redisns}${qname}:Q`, "vt", "delay", "maxsize"], |
| 32 | ["time"] |
| 33 | ]; |
| 34 | this.redis.multi(mc).exec((err, resp) => { |
| 35 | if (err) { |
| 36 | this._handleError(cb, err); |
| 37 | return; |
| 38 | } |
| 39 | if (resp[0][0] === null || resp[0][1] === null || resp[0][2] === null) { |
| 40 | this._handleError(cb, "queueNotFound"); |
| 41 | return; |
| 42 | } |
| 43 | const ms = this._formatZeroPad(Number(resp[1][1]), 6); |
| 44 | const ts = Number(resp[1][0] + ms.toString(10).slice(0, 3)); |
| 45 | const q = { |
| 46 | vt: parseInt(resp[0][0], 10), |
| 47 | delay: parseInt(resp[0][1], 10), |
| 48 | maxsize: parseInt(resp[0][2], 10), |
| 49 | ts: ts |
| 50 | }; |
| 51 | if (uid) { |
| 52 | uid = this._makeid(22); |
| 53 | q.uid = Number(resp[1][0] + ms).toString(36) + uid; |
| 54 | } |
| 55 | cb(null, q); |
| 56 | }); |
| 57 | }; |
| 58 | this.changeMessageVisibility = (options, cb) => { |
| 59 | if (this._validate(options, ["qname", "id", "vt"], cb) === false) |
| 60 | return; |
| 61 | this._getQueue(options.qname, false, (err, q) => { |
| 62 | if (err) { |
| 63 | this._handleError(cb, err); |
| 64 | return; |
nothing calls this directly
no test coverage detected