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 2 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 @@ -197,10 +197,11 @@ Pipeline.prototype.execBuffer = util.deprecate(function () {
return execBuffer.apply(this, arguments);
}, 'Pipeline#execBuffer: Use Pipeline#exec instead');

var exec = Pipeline.prototype.exec;
Pipeline.prototype.exec = function (callback) {
if (this._transactions > 0) {
this._transactions -= 1;
return execBuffer.apply(this, arguments);
return exec.apply(this, arguments);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return (this.options.dropBufferSupport ? exec : execBuffer).apply(this, arguments); should fix the tests in "test/functional/transaction.js"

}
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
4 changes: 2 additions & 2 deletions test/functional/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('transaction', function () {
if (!--pending) {
done();
}
}).hgetallBuffer('foo').get('foo').getBuffer('foo').exec(function (err, res) {
}).hgetallBuffer('foo').get('foo').getBuffer('foo').execBuffer(function (err, res) {
expect(res[0][1]).to.eql('OK');
expect(res[1][1]).to.eql(data);
expect(res[2][1]).to.eql({
Expand All @@ -101,7 +101,7 @@ describe('transaction', function () {
var redis = new Redis();
var data = { name: 'Bob', age: '17' };
redis.pipeline().hmset('foo', data).multi().typeBuffer('foo')
.hgetall('foo').exec().hgetall('foo').exec(function (err, res) {
.hgetall('foo').execBuffer().hgetall('foo').exec(function (err, res) {
expect(res[0][1]).to.eql('OK');
expect(res[1][1]).to.eql('OK');
expect(res[2][1]).to.eql(new Buffer('QUEUED'));
Expand Down