diff --git a/lib/queue.js b/lib/queue.js index 8a627b5..8782a52 100644 --- a/lib/queue.js +++ b/lib/queue.js @@ -231,7 +231,7 @@ TQueue.prototype.uniquePop = function (type, count,cb) { function tryPop(cb) { async.waterfall([ function getData(next) { - queue.redis.lindex(list, -1, next); + queue.redis.lindex(list, type === 'fifo' ? 0 : -1, next); }, function pop(data, next) { if (! data) return next(null, null); diff --git a/test/queue.js b/test/queue.js index 213afaa..faa94e3 100644 --- a/test/queue.js +++ b/test/queue.js @@ -259,6 +259,62 @@ describe('Taskman queue', function () { ], done); }); + it('should pop in the right direction (#fifo)', function (done) { + async.series([ + function push(next) { + queue.push('test1', next); + }, + function push(next) { + queue.push('test2', next); + }, + function pop(next) { + queue.pop('fifo', 1, function (err, data) { + if (err) return next(err); + expect(data).to.eql(['test1']); + next(); + }); + }, + function pop(next) { + queue.pop('fifo', 1, function (err, data) { + if (err) return next(err); + expect(data).to.eql(['test2']); + next(); + }); + } + ], function (err) { + if (err) return done(err); + done(); + }); + }); + + it('should pop in the right direction (#lifo)', function (done) { + async.series([ + function push(next) { + queue.push('test1', next); + }, + function push(next) { + queue.push('test2', next); + }, + function pop(next) { + queue.pop('lifo', 1, function (err, data) { + if (err) return next(err); + expect(data).to.eql(['test2']); + next(); + }); + }, + function pop(next) { + queue.pop('lifo', 1, function (err, data) { + if (err) return next(err); + expect(data).to.eql(['test1']); + next(); + }); + } + ], function (err) { + if (err) return done(err); + done(); + }); + }); + it('should fetch multiple values', function (done) { async.series([ function pushList(next) {