Skip to content

Commit

Permalink
fix transaction with dropBufferSupport:true (#314)
Browse files Browse the repository at this point in the history
Closes #313
  • Loading branch information
shaharmor authored and luin committed Jun 1, 2016
1 parent 7add859 commit 47a2d9a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Pipeline.prototype.multi = function () {
};

var execBuffer = Pipeline.prototype.execBuffer;
var exec = Pipeline.prototype.exec;
Pipeline.prototype.execBuffer = util.deprecate(function () {
if (this._transactions > 0) {
this._transactions -= 1;
Expand All @@ -200,7 +201,7 @@ Pipeline.prototype.execBuffer = util.deprecate(function () {
Pipeline.prototype.exec = function (callback) {
if (this._transactions > 0) {
this._transactions -= 1;
return execBuffer.apply(this, arguments);
return (this.options.dropBufferSupport ? exec : execBuffer).apply(this, arguments);
}
if (!this.nodeifiedPromise) {
this.nodeifiedPromise = true;
Expand Down
28 changes: 28 additions & 0 deletions test/functional/drop_buffer_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,44 @@ describe('dropBufferSupport', function () {
expect(err).to.eql(null);
expect(res[0][1]).to.eql('OK');
expect(res[1][1]).to.eql('bar');
redis.disconnect();
done();
});
});

it('should work with transaction', function (done) {
var redis = new Redis({ dropBufferSupport: true });
redis.multi()
.set('foo', 'bar')
.get('foo')
.exec(function(err, res) {
expect(err).to.eql(null);
expect(res[0][1]).to.eql('OK');
expect(res[1][1]).to.eql('bar');
redis.disconnect();
done();
});
});

it('should fail early with Buffer transaction', function (done) {
var redis = new Redis({ dropBufferSupport: true });
redis.multi()
.set('foo', 'bar')
.getBuffer(new Buffer('foo'), function(err) {
expect(err.message).to.match(/Buffer methods are not available/);
redis.disconnect();
done();
});
});

it('should work with internal select command', function (done) {
var redis = new Redis({ dropBufferSupport: true, db: 1 });
var check = new Redis({ db: 1 });
redis.set('foo', 'bar', function () {
check.get('foo', function (err, res) {
expect(res).to.eql('bar');
redis.disconnect();
check.disconnect();
done();
});
});
Expand Down

0 comments on commit 47a2d9a

Please sign in to comment.