Skip to content

Commit

Permalink
fix semgrep
Browse files Browse the repository at this point in the history
Signed-off-by: Shoham Elias <[email protected]>
  • Loading branch information
shohamazon committed Aug 19, 2024
1 parent 9f026d5 commit 453160a
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions utils/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,21 @@ export class RedisCluster {

private static async detectVersion(): Promise<string> {
return new Promise<string>((resolve, reject) => {
// Helper function to execute a command and parse the version
const getVersion = (command: string): Promise<string> => {
return new Promise<string>((resolve, reject) => {
exec(command, (error, stdout) => {
// First, try with `valkey-server -v`
exec("valkey-server -v", (error, stdout) => {
if (error) {
// If `valkey-server` fails, try `redis-server -v`
exec("redis-server -v", (error, stdout) => {
if (error) {
reject(error);
} else {
const versionMatch = stdout.match(/v=([^\s]+)/);

if (versionMatch) {
resolve(versionMatch[1]);
} else {
reject(
new Error("Version not found in output")
);
}
resolve(stdout.split("v=")[1].split(" ")[0]);
}
});
});
};

// Attempt to get the version from valkey-server first
getVersion("valkey-server -v")
.then(resolve)
.catch(() => {
// If valkey-server fails, attempt to get the version from redis-server
getVersion("redis-server -v").then(resolve).catch(reject);
});
}

resolve(stdout.split("v=")[1].split(" ")[0]);
});
});
}

Expand Down

0 comments on commit 453160a

Please sign in to comment.