Skip to content
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
11 changes: 10 additions & 1 deletion packages/client/lib/cluster/cluster-slots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import RedisClusterSlots from './cluster-slots';

describe('RedisClusterSlots', () => {
describe('initialization', () => {

describe('clientSideCache validation', () => {
const mockEmit = ((_event: string | symbol, ..._args: any[]): boolean => true) as EventEmitter['emit'];
const clientSideCacheConfig = { ttl: 0, maxEntries: 0 };
Expand Down Expand Up @@ -45,4 +44,14 @@ describe('RedisClusterSlots', () => {
});
});
});

describe('getRandomNode', ()=> {
it('should not enter infinite loop when no nodes', () => {
const slots = new RedisClusterSlots({
rootNodes: []
}, () => true)
slots.getRandomNode()
slots.getRandomNode()
});
});
});
3 changes: 2 additions & 1 deletion packages/client/lib/cluster/cluster-slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ export default class RedisClusterSlots<
}

*#iterateAllNodes() {
if(this.masters.length + this.replicas.length === 0) return
let i = Math.floor(Math.random() * (this.masters.length + this.replicas.length));
if (i < this.masters.length) {
do {
Expand Down Expand Up @@ -542,7 +543,7 @@ export default class RedisClusterSlots<
this.masters[index] :
this.replicas[index - this.masters.length],
client = this.#createClient(node, false);

this.pubSubNode = {
address: node.address,
client,
Expand Down
Loading