Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix transaction with dropBufferSupport:true #314

Merged
merged 3 commits into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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