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 b834291
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions utils/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,29 @@ 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) => {
if (error) {
reject(error);
const getVersion = (command: string): Promise<string> => {
return new Promise<string>((resolve, reject) => {
exec(command, (error, stdout) => {
if (error) {
reject(error);
} else {
const versionMatch = stdout.match(/v=([^\s]+)/);

if (versionMatch) {
resolve(versionMatch[1]);
} else {
const versionMatch = stdout.match(/v=([^\s]+)/);

if (versionMatch) {
resolve(versionMatch[1]);
} else {
reject(
new Error("Version not found in output")
);
}
reject(new Error("Version not found in output"));
}
});
});
};

// 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);
}
});
});
});
};

try {
return await getVersion("valkey-server -v");
} catch {
return await getVersion("redis-server -v");
}
}

public static createCluster(
Expand Down

0 comments on commit b834291

Please sign in to comment.