UNPKG

redis-smq-common

Version:

Provides essential components and utilities shared across RedisSMQ packages.

172 lines 4.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IoredisClientMulti = void 0; const index_js_1 = require("../../errors/index.js"); const index_js_2 = require("../../../errors/index.js"); class IoredisClientMulti { constructor(client) { this.multi = client.multi(); } get(key) { this.multi.get(key); return this; } hget(key, field) { this.multi.hget(key, field); return this; } smembers(key) { this.multi.smembers(key); return this; } hgetall(key) { this.multi.hgetall(key); return this; } zcard(key) { this.multi.zcard(key); return this; } scard(key) { this.multi.scard(key); return this; } llen(key) { this.multi.llen(key); return this; } zscore(key, member) { this.multi.zscore(key, member); return this; } set(key, value, options) { if (options.exists && options.expire) { this.multi.set(key, value, options.expire.mode, options.expire.value, options.exists); } else if (options.expire) { this.multi.set(key, value, options.expire.mode, options.expire.value); } else if (options.exists) { this.multi.set(key, value, options.exists); } else { this.multi.set(key, value); } } incr(key) { this.multi.incr(key); return this; } decr(key) { this.multi.decr(key); return this; } incrby(key, increment) { this.multi.incrby(key, increment); return this; } decrby(key, decrement) { this.multi.decrby(key, decrement); return this; } lrem(key, count, element) { this.multi.lrem(key, count, element); return this; } lpop(key) { this.multi.lpop(key); return this; } lpush(key, element) { this.multi.lpush(key, element); return this; } ltrim(key, start, stop) { this.multi.ltrim(key, start, stop); return this; } rpop(key) { this.multi.rpop(key); return this; } rpush(key, element) { this.multi.rpush(key, element); return this; } zadd(key, score, element) { this.multi.zadd(key, score, element); return this; } zrem(key, element) { this.multi.zrem(key, ...(typeof element === 'string' ? [element] : element)); return this; } sadd(key, element) { this.multi.sadd(key, element); return this; } srem(key, element) { this.multi.srem(key, ...(typeof element === 'string' ? [element] : element)); return this; } hset(key, field, value) { this.multi.hset(key, field, value); return this; } hdel(key, field) { this.multi.hdel(key, ...(typeof field === 'string' ? [field] : field)); return this; } hincrby(key, field, by) { this.multi.hincrby(key, field, by); return this; } pexpire(key, millis) { this.multi.pexpire(key, millis); return this; } expire(key, secs) { this.multi.expire(key, secs); return this; } rpoplpush(source, destination) { this.multi.rpoplpush(source, destination); return this; } del(key) { this.multi.del(...(typeof key === 'string' ? [key] : key)); return this; } exec(cb) { this.multi.exec((err, reply) => { if (err) cb(err); else if (!reply) cb(new index_js_1.WatchedKeysChangedError()); else { const lengths = []; let err = null; for (const i of reply) { if (!Array.isArray(i)) { err = new index_js_2.CallbackInvalidReplyError({ message: 'Expected an array reply from multi.exec()', }); break; } const [error, result] = i; if (error instanceof Error) { err = error; break; } lengths.push(result); } if (err) cb(err); else cb(null, lengths); } }); } } exports.IoredisClientMulti = IoredisClientMulti; //# sourceMappingURL=ioredis-client-multi.js.map