Skip to content

Commit

Permalink
fix: 馃悰 on read select any node
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Dec 16, 2023
1 parent cb5056f commit 25f3d10
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/cluster/RedisCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export class RedisCluster implements Printable {
try {
if (this.stopped) return;
await this.router.rebuild(client, id);
} finally{
} finally {
// Discard the seed client as some clusters always return MOVED errors
// from seed clients.
client.stop();
}
if (this.stopped) return;
Expand Down Expand Up @@ -247,7 +249,7 @@ export class RedisCluster implements Printable {
const slot = calculateSlot(key);
await this.whenRouterReady();
const router = this.router;
const node = write ? router.getMasterNodeForSlot(slot) : router.getRandomReplicaNodeForSlot(slot);
const node = write ? router.getMasterNodeForSlot(slot) : router.getRandomNodeForSlot(slot);
if (node) return await this.ensureNodeHasClient(node);
return await this.getAnyClientOrSeedClient();
}
Expand All @@ -261,6 +263,7 @@ export class RedisCluster implements Printable {
return await client.call(call);
} catch (error) {
if (isMovedError(error)) {
// console.error('MOVED', [client.host, client.port], error);
this.scheduleRoutingTableRebuild();
const redirect = parseMovedError((error as Error).message);
let host = redirect[0] || client.host;
Expand Down
1 change: 1 addition & 0 deletions src/node/RedisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class RedisClient {
encoder.writeCmd(call.args);
}
const buf = encoder.writer.flush();
// console.log(Buffer.from(buf).toString());
this.socket.write(buf);
requests.splice(0, length);
} catch (error) {
Expand Down

0 comments on commit 25f3d10

Please sign in to comment.