Skip to content

Commit

Permalink
Merge pull request #238 from FalkorDB/quit_sentinel
Browse files Browse the repository at this point in the history
Make sure sentinel is closed on quit()
  • Loading branch information
gkorland authored Dec 1, 2024
2 parents 2bed64c + 8532829 commit e5232bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "falkordb",
"version": "6.2.3",
"version": "6.2.4",
"description": "A FalkorDB javascript library",
"license": "MIT",
"main": "./dist/index.js",
Expand Down
16 changes: 16 additions & 0 deletions src/clients/sentinel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function extractDetails(masters: Array<Array<string>>) {

export class Sentinel extends Single {

private sentinelClient!: SingleGraphConnection;

init(falkordb: FalkorDB): Promise<void> {
const redisOption = (this.client.options ?? {}) as TypedRedisClientOptions;
return this.tryConnectSentinelServer(this.client, redisOption, falkordb);
Expand Down Expand Up @@ -50,6 +52,9 @@ export class Sentinel extends Single {
};
const realClient = createClient<{ falkordb: typeof commands }, RedisFunctions, RedisScripts>(serverOptions)

// Save sentinel client to quit on quit()
this.sentinelClient = client;

// Set original client as sentinel and server client as client
this.client = realClient;

Expand Down Expand Up @@ -78,5 +83,16 @@ export class Sentinel extends Single {
})
.connect();
}

async quit() {
const promises = [
super.quit()
];
if (this.sentinelClient) {
const reply = this.sentinelClient.quit();
promises.push(reply.then(() => {}))
}
return Promise.all(promises).then(() => {});
}
}

0 comments on commit e5232bd

Please sign in to comment.