added a new method called isSetMembers takes in an array of values to
test if they are members of a set
v1.18.x
barisusakli 11 years ago
parent 29ad8d2582
commit 76037a5f14

@ -217,13 +217,7 @@ var db = require('./database'),
};
Categories.hasReadCategory = function(cid, uid, callback) {
db.isSetMember('cid:' + cid + ':read_by_uid', uid, function(err, hasRead) {
if(err) {
return callback(false);
}
callback(hasRead);
});
db.isSetMember('cid:' + cid + ':read_by_uid', uid, callback);
};
Categories.getRecentReplies = function(cid, uid, count, callback) {

@ -469,6 +469,24 @@
});
};
module.isSetMembers = function(key, values, callback) {
for (var i=0; i<values.length; ++i) {
values[i] = toString(values[i]);
}
db.collection('objects').findOne({_key:key, members: {$in : values}}, function(err, items) {
if (err) {
return callback(err);
}
values = values.map(function(value) {
return items.members.indexOf(value) !== -1
});
callback(null, values);
});
};
module.isMemberOfSets = function(sets, value, callback) {
value = toString(value);

@ -305,14 +305,32 @@
});
};
module.isSetMembers = function(key, values, callback) {
var multi = redisClient.multi();
for (var i=0; i<values.length; ++i) {
multi.sismember(key, values[i]);
}
multi.exec(function(err, results) {
if (err) {
return callback(err);
}
for (var i=0; i<results.length; ++i) {
results[i] = results[i] === 1;
}
callback(null, results);
});
};
module.isMemberOfSets = function(sets, value, callback) {
var batch = redisClient.multi();
var multi = redisClient.multi();
for (var i = 0, ii = sets.length; i < ii; i++) {
batch.sismember(sets[i], value);
multi.sismember(sets[i], value);
}
batch.exec(callback);
multi.exec(callback);
};
module.getSetMembers = function(key, callback) {

Loading…
Cancel
Save