Add --version support for redis-check-rdb (#9971)

Let's you see which version of redis this tool is part of (similarly to redis-cli and redis-benchmark)
This commit is contained in:
yancz2000 2021-12-21 20:11:18 +08:00 committed by GitHub
parent 1b0968df46
commit 23b6173486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -357,6 +357,20 @@ err:
return 1;
}
static sds checkRdbVersion(void) {
sds version;
version = sdscatprintf(sdsempty(), "%s", REDIS_VERSION);
/* Add git commit and working tree status when available */
if (strtoll(redisGitSHA1(),NULL,16)) {
version = sdscatprintf(version, " (git:%s", redisGitSHA1());
if (strtoll(redisGitDirty(),NULL,10))
version = sdscatprintf(version, "-dirty");
version = sdscat(version, ")");
}
return version;
}
/* RDB check main: called form server.c when Redis is executed with the
* redis-check-rdb alias, on during RDB loading errors.
*
@ -375,6 +389,11 @@ int redis_check_rdb_main(int argc, char **argv, FILE *fp) {
if (argc != 2 && fp == NULL) {
fprintf(stderr, "Usage: %s <rdb-file-name>\n", argv[0]);
exit(1);
} else if (!strcmp(argv[1],"-v") || !strcmp(argv[1], "--version")) {
sds version = checkRdbVersion();
printf("redis-check-rdb %s\n", version);
sdsfree(version);
exit(0);
}
gettimeofday(&tv, NULL);