Skip to content

Commit e42f30f

Browse files
committed
fix(Cluster): empty key name was sent to random nodes
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!
1 parent a2efed5 commit e42f30f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/command.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ Command.prototype.initPromise = function () {
8484
Command.prototype.getSlot = function () {
8585
if (typeof this._slot === 'undefined') {
8686
var key = this.getKeys()[0];
87-
if (key) {
88-
this.slot = calculateSlot(key);
89-
} else {
87+
if (key == null) {
9088
this.slot = null;
89+
} else {
90+
this.slot = calculateSlot(key);
9191
}
9292
}
9393
return this.slot;

test/unit/command.js

+6
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,18 @@ describe('Command', function () {
7777
describe('#getSlot()', function () {
7878
it('should return correctly', function () {
7979
expectSlot('123', 5970);
80+
expectSlot(123, 5970);
8081
expectSlot('ab{c', 4619);
8182
expectSlot('ab{c}2', 7365);
8283
expectSlot('ab{{c}2', 2150);
8384
expectSlot('ab{qq}{c}2', 5598);
8485
expectSlot('ab}', 11817);
8586
expectSlot('encoding', 3060);
87+
expectSlot(true, 13635);
88+
expectSlot('true', 13635);
89+
expectSlot('', 0);
90+
expectSlot(null, 0);
91+
expectSlot(undefined, 0);
8692

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

0 commit comments

Comments
 (0)