2015-12-25 00:42:49 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function UserIndexer(metadataBackend) {
|
|
|
|
this.metadataBackend = metadataBackend;
|
|
|
|
this.db = 5;
|
2015-12-31 03:16:18 +08:00
|
|
|
this.redisPrefix = 'batch:users:';
|
2015-12-25 00:42:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UserIndexer.prototype.add = function (username, job_id, callback) {
|
2016-01-05 02:08:13 +08:00
|
|
|
this.metadataBackend.redisCmd(this.db, 'RPUSH', [ this.redisPrefix + username, job_id ] , callback);
|
2015-12-25 00:42:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
UserIndexer.prototype.list = function (username, callback) {
|
2016-01-05 02:08:13 +08:00
|
|
|
this.metadataBackend.redisCmd(this.db, 'LRANGE', [ this.redisPrefix + username, -100, -1 ] , callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
UserIndexer.prototype.remove = function (username, job_id, callback) {
|
|
|
|
this.metadataBackend.redisCmd(this.db, 'LREM', [ this.redisPrefix + username, 0, job_id] , callback);
|
2015-12-25 00:42:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = UserIndexer;
|