Skip to content

Commit

Permalink
Merge pull request #117 from phlip9/master
Browse files Browse the repository at this point in the history
Fix not running callback in pipeline custom command
  • Loading branch information
luin committed Jul 30, 2015
2 parents acd5ada + 7367fca commit 6c23cde
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Script.prototype.execute = function (container, args, options, callback) {
}).nodeify(callback);
}

// result is not a Promise--probably returned from a pipeline chain; however,
// we still need the callback to fire when the script is evaluated
evalsha.promise.nodeify(callback);

return result;
};

Expand Down
55 changes: 55 additions & 0 deletions test/functional/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,61 @@ describe('pipeline', function () {
});
});

describe('custom commands', function() {
var redis;

before(function() {
redis = new Redis();
redis.defineCommand('echo', {
numberOfKeys: 2,
lua: 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}'
});
});

it('should work', function(done) {
redis.pipeline().echo('foo', 'bar', '123', 'abc').exec(function(err, results) {
expect(err).to.eql(null);
expect(results).to.eql([
[null, ['foo', 'bar', '123', 'abc']]
]);
done();
});
});

it('should support callbacks', function(done) {
var pending = 1;
redis.pipeline()
.echo('foo', 'bar', '123', 'abc', function(err, result) {
pending -= 1;
expect(err).to.eql(null);
expect(result).to.eql(['foo', 'bar', '123', 'abc']);
})
.exec(function(err, results) {
expect(err).to.eql(null);
expect(results).to.eql([
[null, ['foo', 'bar', '123', 'abc']]
]);
expect(pending).to.eql(0);
done();
});
});

it('should be supported in transaction blocks', function(done) {
redis.pipeline()
.multi()
.set('foo', 'asdf')
.echo('bar', 'baz', '123', 'abc')
.get('foo')
.exec()
.exec(function(err, results) {
expect(err).to.eql(null);
expect(results[4][1][1]).to.eql(['bar', 'baz', '123', 'abc']);
expect(results[4][1][2]).to.eql('asdf');
done();
});
});
});

describe('#addBatch', function () {
it('should accept commands in constructor', function (done) {
var redis = new Redis();
Expand Down

0 comments on commit 6c23cde

Please sign in to comment.