2015-12-09 07:02:08 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
2015-12-10 03:17:45 +08:00
|
|
|
function UsernameQueue(metadataBackend) {
|
2015-12-09 19:18:33 +08:00
|
|
|
this.metadataBackend = metadataBackend;
|
|
|
|
this.db = 5;
|
|
|
|
this.queueName = 'usernameBatchQueue';
|
2015-12-09 07:02:08 +08:00
|
|
|
}
|
|
|
|
|
2015-12-10 03:17:45 +08:00
|
|
|
UsernameQueue.prototype.enqueue = function (cdbUsername, callback) {
|
2015-12-09 19:18:33 +08:00
|
|
|
var db = this.db;
|
|
|
|
var queue = this.queueName;
|
2015-12-09 07:02:08 +08:00
|
|
|
|
2015-12-09 19:18:33 +08:00
|
|
|
this.metadataBackend.redisCmd(db, 'LPUSH', [queue, cdbUsername], function (err, cdbUsername) {
|
2015-12-09 07:02:08 +08:00
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
2015-12-09 19:18:33 +08:00
|
|
|
callback(null, cdbUsername);
|
2015-12-09 07:02:08 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-12-10 03:17:45 +08:00
|
|
|
UsernameQueue.prototype.dequeue = function (callback) {
|
2015-12-09 19:18:33 +08:00
|
|
|
var db = this.db;
|
|
|
|
var queue = this.queueName;
|
2015-12-09 07:02:08 +08:00
|
|
|
|
2015-12-09 19:18:33 +08:00
|
|
|
this.metadataBackend.redisCmd(db, 'RPOP', [queue], function (err, cdbUsername) {
|
2015-12-09 07:02:08 +08:00
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
2015-12-09 19:18:33 +08:00
|
|
|
callback(null, cdbUsername);
|
2015-12-09 07:02:08 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-12-10 03:17:45 +08:00
|
|
|
module.exports = UsernameQueue;
|