Skip to content

Commit

Permalink
fix(Cluster): empty key name was sent to random nodes
Browse files Browse the repository at this point in the history
Before this fix, empty key names (""/null/undefined) was
sent to random nodes. That should not be the case when
key name is an empty string.

Related with #390.

Thank Aditya-Chowdhry for addressing this issue!
  • Loading branch information
luin committed Oct 4, 2017
1 parent a2efed5 commit e42f30f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ Command.prototype.initPromise = function () {
Command.prototype.getSlot = function () {
if (typeof this._slot === 'undefined') {
var key = this.getKeys()[0];
if (key) {
this.slot = calculateSlot(key);
} else {
if (key == null) {
this.slot = null;
} else {
this.slot = calculateSlot(key);
}
}
return this.slot;
Expand Down
6 changes: 6 additions & 0 deletions test/unit/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,18 @@ describe('Command', function () {
describe('#getSlot()', function () {
it('should return correctly', function () {
expectSlot('123', 5970);
expectSlot(123, 5970);
expectSlot('ab{c', 4619);
expectSlot('ab{c}2', 7365);
expectSlot('ab{{c}2', 2150);
expectSlot('ab{qq}{c}2', 5598);
expectSlot('ab}', 11817);
expectSlot('encoding', 3060);
expectSlot(true, 13635);
expectSlot('true', 13635);
expectSlot('', 0);
expectSlot(null, 0);
expectSlot(undefined, 0);

function expectSlot(key, slot) {
expect(new Command('get', [key]).getSlot()).to.eql(slot);
Expand Down

0 comments on commit e42f30f

Please sign in to comment.