Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get valkey/redis version using client's info command #2276

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
74dd3dc
Get valkey/redis version using cli command
prateek-kumar-improving Sep 11, 2024
75ed97f
Change log updated
prateek-kumar-improving Sep 11, 2024
147643f
Add validation
prateek-kumar-improving Sep 11, 2024
f94d35d
Type updated for addresses field
prateek-kumar-improving Sep 11, 2024
c00d7bd
Refactor node js code to get version using client's info command
prateek-kumar-improving Sep 12, 2024
69a5f04
Merge branch 'main' into node-get-version-using-cli-command
prateek-kumar-improving Sep 12, 2024
4fd56c9
Merge branch 'main' into node-get-version-using-cli-command
prateek-kumar-improving Sep 12, 2024
cb4e11f
Update RedisCluster to ValkeyServer
prateek-kumar-improving Sep 12, 2024
baa1a0d
Formatting fixed
prateek-kumar-improving Sep 12, 2024
4cd703f
Formatting fixed
prateek-kumar-improving Sep 12, 2024
23ce215
common function moved to TestUtilities
prateek-kumar-improving Sep 12, 2024
131677f
Common function refactored
prateek-kumar-improving Sep 12, 2024
21a3519
Documentation updated
prateek-kumar-improving Sep 12, 2024
a3e8319
fix for cluster client
prateek-kumar-improving Sep 12, 2024
b1a9643
Formatting callback function parameter
prateek-kumar-improving Sep 12, 2024
ee4cd15
refactoring pubSub callback call
prateek-kumar-improving Sep 12, 2024
4fa5191
Pub sub cluster client parameter updated
prateek-kumar-improving Sep 12, 2024
39171e6
Merge branch 'main' into node-get-version-using-cli-command
prateek-kumar-improving Sep 12, 2024
0a95e8c
formatting fixed
prateek-kumar-improving Sep 12, 2024
fdd3112
Change log updated
prateek-kumar-improving Sep 12, 2024
21aa6ac
Change log updated
prateek-kumar-improving Sep 12, 2024
9d43017
callback refactored
prateek-kumar-improving Sep 12, 2024
43b7d96
initFromExistingCluster cluster_mode added
prateek-kumar-improving Sep 12, 2024
c96fc9d
Merge branch 'main' into node-get-version-using-cli-command
prateek-kumar-improving Sep 12, 2024
c861846
clients closed
prateek-kumar-improving Sep 12, 2024
29d4f6c
Glide cluster client closed
prateek-kumar-improving Sep 12, 2024
8d38dfe
Files formatted
prateek-kumar-improving Sep 12, 2024
e244aaa
Cluster mode added in client close
prateek-kumar-improving Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Node: Get valkey/redis version using cli command ([#2276]https://github.com/valkey-io/valkey-glide/pull/2276)
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
* Java: Fetch server version using info command ([#2258](https://github.com/valkey-io/valkey-glide/pull/2258))
* Node: Added binary variant for commands which have `Record` as input or output ([#2207](https://github.com/valkey-io/valkey-glide/pull/2207))
* Node: Renamed `ReturnType` to `GlideReturnType` ([#2241](https://github.com/valkey-io/valkey-glide/pull/2241))
Expand Down
8 changes: 4 additions & 4 deletions node/tests/GlideClusterClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import {
ClusterTransaction,
convertRecordToGlideRecord,
Decoder,
FlushMode,
FunctionListResponse,
FunctionRestorePolicy,
FunctionStatsSingleResponse,
GeoUnit,
GlideClusterClient,
GlideReturnType,
InfoOptions,
Expand All @@ -27,10 +31,6 @@ import {
Routes,
ScoreFilter,
SlotKeyTypes,
FlushMode,
FunctionRestorePolicy,
FunctionStatsSingleResponse,
GeoUnit,
SortOrder,
} from "..";
import { RedisCluster } from "../../utils/TestUtils.js";
Expand Down
59 changes: 32 additions & 27 deletions utils/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
.split(",")
.map((address) => address.split(":"))
.map((address) => [address[0], Number(address[1])]) as [
string,
number
][];
string,
number
][];

if (clusterFolder === undefined || ports === undefined) {
throw new Error(`Insufficient data in input: ${input}`);
Expand All @@ -50,26 +50,34 @@
this.version = version;
}

private static async detectVersion(): Promise<string> {
private static async detectVersion(addresses: [string, number][]): Promise<string> {
return new Promise<string>((resolve, reject) => {
const extractVersion = (stdout: string): string =>
stdout.split("v=")[1].split(" ")[0];

// 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 {
resolve(extractVersion(stdout));
}
});
} else {
resolve(extractVersion(stdout));
}
});
const redisVersionKey = "redis_version:";
const valkeyVersionKey = "valkey_version:";
const extractVersion = (versionKey: string, stdout: string): string =>
stdout.split(versionKey)[1].split("\n")[0];
if (addresses.length > 0 && addresses[0].length > 1) {
let redisInfoCommand = "redis-cli -h " + addresses[0][0] + " -p " + addresses[0][1] + " info";
Fixed Show fixed Hide fixed
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
let valkeyInfoCommand = "valkey-cli -h " + addresses[0][0] + " -p " + addresses[0][1] + " info";
Fixed Show fixed Hide fixed

//First, try with `valkey-server -v`
exec(valkeyInfoCommand, (error, stdout) => {
if (error) {
// If `valkey-server` fails, try `redis-server -v`
exec(redisInfoCommand, (error, stdout) => {
if (error) {
reject(error);
} else {
resolve(extractVersion(redisVersionKey, stdout));
}
});
} else {
resolve(extractVersion(valkeyVersionKey, stdout));
}
});
} else {
reject("Addresses not found for getting valkey/redis version");
}
});
}

Expand Down Expand Up @@ -98,20 +106,17 @@
}
}

console.log(command);
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
execFile(
"python3",
[PY_SCRIPT_PATH, ...command.split(" ")],
(error, stdout, stderr) => {
if (error) {
console.error(stderr);
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
reject(error);
} else {
const { clusterFolder, addresses: ports } =
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
parseOutput(stdout);

resolve(
RedisCluster.detectVersion().then(
RedisCluster.detectVersion(ports).then(
(ver) =>
new RedisCluster(ver, ports, clusterFolder)
)
Expand All @@ -125,7 +130,7 @@
public static async initFromExistingCluster(
addresses: [string, number][]
): Promise<RedisCluster> {
return RedisCluster.detectVersion().then(
return RedisCluster.detectVersion(addresses).then(
(ver) => new RedisCluster(ver, addresses, "")
);
}
Expand Down
Loading