redis-smq-common
Version:
RedisSMQ Common Library provides many components that are mainly used by RedisSMQ and RedisSMQ Monitor.
104 lines • 2.9 kB
JavaScript
import { RedisClientError, WatchedKeysChangedError, } from '../../errors/index.js';
export class IoredisClientMulti {
multi;
constructor(client) {
this.multi = client.multi();
}
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 WatchedKeysChangedError());
else {
const lengths = [];
let err = null;
for (const i of reply) {
if (!Array.isArray(i)) {
err = new RedisClientError('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);
}
});
}
}
//# sourceMappingURL=ioredis-client-multi.js.map