Skip to content

Commit 47a2d9a

Browse files
shaharmorluin
authored andcommitted
fix transaction with dropBufferSupport:true (#314)
Closes #313
1 parent 7add859 commit 47a2d9a

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/pipeline.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ Pipeline.prototype.multi = function () {
190190
};
191191

192192
var execBuffer = Pipeline.prototype.execBuffer;
193+
var exec = Pipeline.prototype.exec;
193194
Pipeline.prototype.execBuffer = util.deprecate(function () {
194195
if (this._transactions > 0) {
195196
this._transactions -= 1;
@@ -200,7 +201,7 @@ Pipeline.prototype.execBuffer = util.deprecate(function () {
200201
Pipeline.prototype.exec = function (callback) {
201202
if (this._transactions > 0) {
202203
this._transactions -= 1;
203-
return execBuffer.apply(this, arguments);
204+
return (this.options.dropBufferSupport ? exec : execBuffer).apply(this, arguments);
204205
}
205206
if (!this.nodeifiedPromise) {
206207
this.nodeifiedPromise = true;

test/functional/drop_buffer_support.js

+28
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,44 @@ describe('dropBufferSupport', function () {
8484
expect(err).to.eql(null);
8585
expect(res[0][1]).to.eql('OK');
8686
expect(res[1][1]).to.eql('bar');
87+
redis.disconnect();
8788
done();
8889
});
8990
});
9091

92+
it('should work with transaction', function (done) {
93+
var redis = new Redis({ dropBufferSupport: true });
94+
redis.multi()
95+
.set('foo', 'bar')
96+
.get('foo')
97+
.exec(function(err, res) {
98+
expect(err).to.eql(null);
99+
expect(res[0][1]).to.eql('OK');
100+
expect(res[1][1]).to.eql('bar');
101+
redis.disconnect();
102+
done();
103+
});
104+
});
105+
106+
it('should fail early with Buffer transaction', function (done) {
107+
var redis = new Redis({ dropBufferSupport: true });
108+
redis.multi()
109+
.set('foo', 'bar')
110+
.getBuffer(new Buffer('foo'), function(err) {
111+
expect(err.message).to.match(/Buffer methods are not available/);
112+
redis.disconnect();
113+
done();
114+
});
115+
});
116+
91117
it('should work with internal select command', function (done) {
92118
var redis = new Redis({ dropBufferSupport: true, db: 1 });
93119
var check = new Redis({ db: 1 });
94120
redis.set('foo', 'bar', function () {
95121
check.get('foo', function (err, res) {
96122
expect(res).to.eql('bar');
123+
redis.disconnect();
124+
check.disconnect();
97125
done();
98126
});
99127
});

0 commit comments

Comments
 (0)