Skip to content

Commit

Permalink
fix: 馃悰 correctly sort router nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Dec 15, 2023
1 parent 6faf3ab commit fb98f63
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/cluster/RedisCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ export class RedisCluster implements Printable {
return await client.call(call);
} catch (error) {
if (isMovedError(error)) {
console.log('MOVED', error);
this.scheduleRoutingTableRebuild();
const redirect = parseMovedError((error as Error).message);
let host = redirect[0] || client.host;
Expand Down
5 changes: 3 additions & 2 deletions src/cluster/RedisClusterRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {RedisCluster} from './RedisCluster';
import type {RedisClusterNodeClient} from './RedisClusterNodeClient';

export class RedisClusterRouter implements Printable {
/** Map of slots ordered by slot end (max) value. */
/** Map of slots ordered by slot end (min) value. */
protected readonly ranges = new AvlMap<number, RedisClusterSlotRange>();

/** Map of node ID to node info instance. */
Expand All @@ -34,6 +34,7 @@ export class RedisClusterRouter implements Printable {
this.ranges.clear();
this.byId.clear();
this.byHostAndPort.clear();
if (!slots.length) throw new Error('NO_SLOTS');
for (const slot of slots) {
const range = new RedisClusterSlotRange(slot.slots[0], slot.slots[1], []);
for (const nodeInfo of slot.nodes) {
Expand All @@ -43,7 +44,7 @@ export class RedisClusterRouter implements Printable {
this.setNode(node);
range.nodes.push(node);
}
this.ranges.insert(range.max, range);
this.ranges.insert(range.min, range);
}
// TODO: remove orphan clients
}
Expand Down

0 comments on commit fb98f63

Please sign in to comment.