feat: if only one value is passed used faster function

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 981db6429a
commit 2587112f9d

@ -235,24 +235,25 @@ module.exports = function (module) {
} }
module.sortedSetRanks = async function (key, values) { module.sortedSetRanks = async function (key, values) {
return await sortedSetRanks(module.getSortedSetRange, key, values); return await sortedSetRanks(false, key, values);
}; };
module.sortedSetRevRanks = async function (key, values) { module.sortedSetRevRanks = async function (key, values) {
return await sortedSetRanks(module.getSortedSetRevRange, key, values); return await sortedSetRanks(true, key, values);
}; };
async function sortedSetRanks(method, key, values) { async function sortedSetRanks(reverse, key, values) {
const sortedSet = await method(key, 0, -1); if (values.length === 1) {
return [await getSortedSetRank(reverse, key, values[0])];
var result = values.map(function (value) { }
const sortedSet = await module[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](key, 0, -1);
return values.map(function (value) {
if (!value) { if (!value) {
return null; return null;
} }
var index = sortedSet.indexOf(value.toString()); const index = sortedSet.indexOf(value.toString());
return index !== -1 ? index : null; return index !== -1 ? index : null;
}); });
return result;
} }
module.sortedSetScore = async function (key, value) { module.sortedSetScore = async function (key, value) {

Loading…
Cancel
Save