v1.18.x
Baris Usakli 6 years ago
parent e3bf21a3a0
commit 7b9a2caec3

@ -75,7 +75,7 @@ module.exports = function (redisClient, module) {
async.waterfall([
function (next) {
if (unCachedKeys.length > 1) {
helpers.multiKeys(redisClient, 'hgetall', unCachedKeys, next);
helpers.execKeys(redisClient, 'batch', 'hgetall', unCachedKeys, next);
} else {
redisClient.hgetall(unCachedKeys[0], (err, data) => next(err, [data]));
}
@ -139,7 +139,7 @@ module.exports = function (redisClient, module) {
};
module.isObjectFields = function (key, fields, callback) {
helpers.multiKeyValues(redisClient, 'hexists', key, fields, function (err, results) {
helpers.execKeyValues(redisClient, 'batch', 'hexists', key, fields, function (err, results) {
callback(err, Array.isArray(results) ? helpers.resultsToBool(results) : null);
});
};
@ -156,7 +156,7 @@ module.exports = function (redisClient, module) {
};
module.deleteObjectFields = function (key, fields, callback) {
helpers.multiKeyValues(redisClient, 'hdel', key, fields, function (err) {
helpers.execKeyValues(redisClient, 'batch', 'hdel', key, fields, function (err) {
cache.delObjectCache(key);
callback(err);
});
@ -184,11 +184,11 @@ module.exports = function (redisClient, module) {
return callback(null, null);
}
if (Array.isArray(key)) {
var multi = redisClient.multi();
var batch = redisClient.batch();
key.forEach(function (key) {
multi.hincrby(key, field, value);
batch.hincrby(key, field, value);
});
multi.exec(done);
batch.exec(done);
} else {
redisClient.hincrby(key, field, value, done);
}

@ -4,31 +4,31 @@ var helpers = module.exports;
helpers.noop = function () {};
helpers.multiKeys = function (redisClient, command, keys, callback) {
helpers.execKeys = function (redisClient, type, command, keys, callback) {
callback = callback || function () {};
var multi = redisClient.multi();
var queue = redisClient[type]();
for (var i = 0; i < keys.length; i += 1) {
multi[command](keys[i]);
queue[command](keys[i]);
}
multi.exec(callback);
queue.exec(callback);
};
helpers.multiKeysValue = function (redisClient, command, keys, value, callback) {
helpers.execKeysValue = function (redisClient, type, command, keys, value, callback) {
callback = callback || function () {};
var multi = redisClient.multi();
var queue = redisClient[type]();
for (var i = 0; i < keys.length; i += 1) {
multi[command](String(keys[i]), String(value));
queue[command](String(keys[i]), String(value));
}
multi.exec(callback);
queue.exec(callback);
};
helpers.multiKeyValues = function (redisClient, command, key, values, callback) {
helpers.execKeyValues = function (redisClient, type, command, key, values, callback) {
callback = callback || function () {};
var multi = redisClient.multi();
var queue = redisClient[type]();
for (var i = 0; i < values.length; i += 1) {
multi[command](String(key), String(values[i]));
queue[command](String(key), String(values[i]));
}
multi.exec(callback);
queue.exec(callback);
};
helpers.resultsToBool = function (results) {

@ -23,7 +23,7 @@ module.exports = function (redisClient, module) {
module.exists = function (key, callback) {
if (Array.isArray(key)) {
helpers.multiKeys(redisClient, 'exists', key, function (err, data) {
helpers.execKeys(redisClient, 'batch', 'exists', key, function (err, data) {
callback(err, data && data.map(exists => exists === 1));
});
} else {
@ -43,11 +43,11 @@ module.exports = function (redisClient, module) {
module.deleteAll = function (keys, callback) {
callback = callback || function () {};
var multi = redisClient.multi();
var batch = redisClient.batch();
for (var i = 0; i < keys.length; i += 1) {
multi.del(keys[i]);
batch.del(keys[i]);
}
multi.exec(function (err) {
batch.exec(function (err) {
module.objectCache.delObjectCache(keys);
callback(err);
});

@ -18,7 +18,7 @@ module.exports = function (redisClient, module) {
module.setsAdd = function (keys, value, callback) {
callback = callback || function () {};
helpers.multiKeysValue(redisClient, 'sadd', keys, value, function (err) {
helpers.execKeysValue(redisClient, 'batch', 'sadd', keys, value, function (err) {
callback(err);
});
};
@ -31,18 +31,19 @@ module.exports = function (redisClient, module) {
if (!Array.isArray(key)) {
key = [key];
}
var multi = redisClient.multi();
var batch = redisClient.batch();
key.forEach(function (key) {
multi.srem(key, value);
batch.srem(key, value);
});
multi.exec(function (err) {
batch.exec(function (err) {
callback(err);
});
};
module.setsRemove = function (keys, value, callback) {
callback = callback || function () {};
helpers.multiKeysValue(redisClient, 'srem', keys, value, function (err) {
helpers.execKeysValue(redisClient, 'batch', 'srem', keys, value, function (err) {
callback(err);
});
};
@ -54,13 +55,13 @@ module.exports = function (redisClient, module) {
};
module.isSetMembers = function (key, values, callback) {
helpers.multiKeyValues(redisClient, 'sismember', key, values, function (err, results) {
helpers.execKeyValues(redisClient, 'batch', 'sismember', key, values, function (err, results) {
callback(err, results ? helpers.resultsToBool(results) : null);
});
};
module.isMemberOfSets = function (sets, value, callback) {
helpers.multiKeysValue(redisClient, 'sismember', sets, value, function (err, results) {
helpers.execKeysValue(redisClient, 'batch', 'sismember', sets, value, function (err, results) {
callback(err, results ? helpers.resultsToBool(results) : null);
});
};
@ -70,7 +71,7 @@ module.exports = function (redisClient, module) {
};
module.getSetsMembers = function (keys, callback) {
helpers.multiKeys(redisClient, 'smembers', keys, callback);
helpers.execKeys(redisClient, 'batch', 'smembers', keys, callback);
};
module.setCount = function (key, callback) {
@ -78,7 +79,7 @@ module.exports = function (redisClient, module) {
};
module.setsCount = function (keys, callback) {
helpers.multiKeys(redisClient, 'scard', keys, callback);
helpers.execKeys(redisClient, 'batch', 'scard', keys, callback);
};
module.setRemoveRandom = function (key, callback) {

@ -92,11 +92,11 @@ module.exports = function (redisClient, module) {
if (Array.isArray(keys) && !keys.length) {
return callback(null, []);
}
var multi = redisClient.multi();
var batch = redisClient.batch();
for (var i = 0; i < keys.length; i += 1) {
multi.zcard(keys[i]);
batch.zcard(keys[i]);
}
multi.exec(callback);
batch.exec(callback);
};
module.sortedSetRank = function (key, value, callback) {
@ -104,19 +104,19 @@ module.exports = function (redisClient, module) {
};
module.sortedSetsRanks = function (keys, values, callback) {
var multi = redisClient.multi();
var batch = redisClient.batch();
for (var i = 0; i < values.length; i += 1) {
multi.zrank(keys[i], values[i]);
batch.zrank(keys[i], values[i]);
}
multi.exec(callback);
batch.exec(callback);
};
module.sortedSetRanks = function (key, values, callback) {
var multi = redisClient.multi();
var batch = redisClient.batch();
for (var i = 0; i < values.length; i += 1) {
multi.zrank(key, values[i]);
batch.zrank(key, values[i]);
}
multi.exec(callback);
batch.exec(callback);
};
module.sortedSetRevRank = function (key, value, callback) {
@ -140,11 +140,11 @@ module.exports = function (redisClient, module) {
};
module.sortedSetsScore = function (keys, value, callback) {
helpers.multiKeysValue(redisClient, 'zscore', keys, value, callback);
helpers.execKeysValue(redisClient, 'batch', 'zscore', keys, value, callback);
};
module.sortedSetScores = function (key, values, callback) {
helpers.multiKeyValues(redisClient, 'zscore', key, values, callback);
helpers.execKeyValues(redisClient, 'batch', 'zscore', key, values, callback);
};
module.isSortedSetMember = function (key, value, callback) {
@ -154,7 +154,7 @@ module.exports = function (redisClient, module) {
};
module.isSortedSetMembers = function (key, values, callback) {
helpers.multiKeyValues(redisClient, 'zscore', key, values, function (err, results) {
helpers.execKeyValues(redisClient, 'batch', 'zscore', key, values, function (err, results) {
if (err) {
return callback(err);
}
@ -163,7 +163,7 @@ module.exports = function (redisClient, module) {
};
module.isMemberOfSortedSets = function (keys, value, callback) {
helpers.multiKeysValue(redisClient, 'zscore', keys, value, function (err, results) {
helpers.execKeysValue(redisClient, 'batch', 'zscore', keys, value, function (err, results) {
if (err) {
return callback(err);
}
@ -175,11 +175,11 @@ module.exports = function (redisClient, module) {
if (!Array.isArray(keys) || !keys.length) {
return setImmediate(callback, null, []);
}
var multi = redisClient.multi();
var batch = redisClient.batch();
for (var i = 0; i < keys.length; i += 1) {
multi.zrange(keys[i], 0, -1);
batch.zrange(keys[i], 0, -1);
}
multi.exec(callback);
batch.exec(callback);
};
module.sortedSetIncrBy = function (key, increment, value, callback) {

@ -39,15 +39,15 @@ module.exports = function (redisClient, module) {
if (!Array.isArray(keys) || !keys.length) {
return callback();
}
var multi = redisClient.multi();
var batch = redisClient.batch();
for (var i = 0; i < keys.length; i += 1) {
if (keys[i]) {
multi.zadd(keys[i], score, value);
batch.zadd(keys[i], score, value);
}
}
multi.exec(function (err) {
batch.exec(function (err) {
callback(err);
});
};

@ -14,33 +14,33 @@ module.exports = function (redisClient, module) {
}
if (Array.isArray(key)) {
var multi = redisClient.multi();
var batch = redisClient.batch();
key.forEach(function (key) {
multi.zrem(key, value);
batch.zrem(key, value);
});
multi.exec(function (err) {
batch.exec(function (err) {
callback(err);
});
} else {
helpers.multiKeyValues(redisClient, 'zrem', key, value, function (err) {
helpers.execKeyValues(redisClient, 'batch', 'zrem', key, value, function (err) {
callback(err);
});
}
};
module.sortedSetsRemove = function (keys, value, callback) {
helpers.multiKeysValue(redisClient, 'zrem', keys, value, function (err) {
helpers.execKeysValue(redisClient, 'batch', 'zrem', keys, value, function (err) {
callback(err);
});
};
module.sortedSetsRemoveRangeByScore = function (keys, min, max, callback) {
callback = callback || function () {};
var multi = redisClient.multi();
var batch = redisClient.batch();
for (var i = 0; i < keys.length; i += 1) {
multi.zremrangebyscore(keys[i], min, max);
batch.zremrangebyscore(keys[i], min, max);
}
multi.exec(function (err) {
batch.exec(function (err) {
callback(err);
});
};

Loading…
Cancel
Save