Move cliVersion to cli_common and add --version support for redis-check-aof (#10856)
Let us see which version of redis this tool is part of. Similarly to redis-cli, redis-benchmark and redis-check-rdb redis-rdb-check and redis-aof-check are actually symlinks to redis, so they will directly use getVersion in server, the format became: ``` {title} v={redis_version} sha={sha}:{dirty} malloc={malloc} bits={bits} build={build} ``` Move cliVersion into cli_common, redis-cli and redis-benchmark will use it, and the format is not change: ``` {title} {redis_version} (git:{sha}) ```
This commit is contained in:
parent
5dc631d880
commit
23e980e77a
|
@ -30,6 +30,8 @@
|
|||
|
||||
#include "fmacros.h"
|
||||
#include "cli_common.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -48,6 +50,9 @@
|
|||
|
||||
#define UNUSED(V) ((void) V)
|
||||
|
||||
char *redisGitSHA1(void);
|
||||
char *redisGitDirty(void);
|
||||
|
||||
/* Wrapper around redisSecureConnection to avoid hiredis_ssl dependencies if
|
||||
* not building with TLS support.
|
||||
*/
|
||||
|
@ -406,3 +411,16 @@ sds escapeJsonString(sds s, const char *p, size_t len) {
|
|||
}
|
||||
return sdscatlen(s,"\"",1);
|
||||
}
|
||||
|
||||
sds cliVersion(void) {
|
||||
sds 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;
|
||||
}
|
||||
|
|
|
@ -51,4 +51,6 @@ void freeCliConnInfo(cliConnInfo connInfo);
|
|||
|
||||
sds escapeJsonString(sds s, const char *p, size_t len);
|
||||
|
||||
sds cliVersion(void);
|
||||
|
||||
#endif /* __CLICOMMON_H */
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
*/
|
||||
|
||||
#include "fmacros.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -186,8 +185,6 @@ typedef struct redisConfig {
|
|||
} redisConfig;
|
||||
|
||||
/* Prototypes */
|
||||
char *redisGitSHA1(void);
|
||||
char *redisGitDirty(void);
|
||||
static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask);
|
||||
static void createMissingClients(client c);
|
||||
static benchmarkThread *createBenchmarkThread(int index);
|
||||
|
@ -205,20 +202,6 @@ static void updateClusterSlotsConfiguration(void);
|
|||
int showThroughput(struct aeEventLoop *eventLoop, long long id,
|
||||
void *clientData);
|
||||
|
||||
static sds benchmarkVersion(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;
|
||||
}
|
||||
|
||||
/* Dict callbacks */
|
||||
static uint64_t dictSdsHash(const void *key);
|
||||
static int dictSdsKeyCompare(dict *d, const void *key1, const void *key2);
|
||||
|
@ -1423,7 +1406,7 @@ int parseOptions(int argc, char **argv) {
|
|||
if (lastarg) goto invalid;
|
||||
config.numclients = atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i],"-v") || !strcmp(argv[i], "--version")) {
|
||||
sds version = benchmarkVersion();
|
||||
sds version = cliVersion();
|
||||
printf("redis-benchmark %s\n", version);
|
||||
sdsfree(version);
|
||||
exit(0);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
*/
|
||||
|
||||
#include "server.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <regex.h>
|
||||
|
@ -515,6 +516,13 @@ int redis_check_aof_main(int argc, char **argv) {
|
|||
if (argc < 2) {
|
||||
goto invalid_args;
|
||||
} else if (argc == 2) {
|
||||
if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) {
|
||||
sds version = getVersion();
|
||||
printf("redis-check-aof %s\n", version);
|
||||
sdsfree(version);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
filepath = argv[1];
|
||||
} else if (argc == 3) {
|
||||
if (!strcmp(argv[1], "--fix")) {
|
||||
|
|
|
@ -394,20 +394,6 @@ 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.
|
||||
*
|
||||
|
@ -427,7 +413,7 @@ int redis_check_rdb_main(int argc, char **argv, FILE *fp) {
|
|||
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();
|
||||
sds version = getVersion();
|
||||
printf("redis-check-rdb %s\n", version);
|
||||
sdsfree(version);
|
||||
exit(0);
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
*/
|
||||
|
||||
#include "fmacros.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -64,7 +63,6 @@
|
|||
#include "connection.h"
|
||||
#include "cli_common.h"
|
||||
#include "mt19937-64.h"
|
||||
|
||||
#include "cli_commands.h"
|
||||
|
||||
#define UNUSED(V) ((void) V)
|
||||
|
@ -287,8 +285,6 @@ static struct pref {
|
|||
static volatile sig_atomic_t force_cancel_loop = 0;
|
||||
static void usage(int err);
|
||||
static void slaveMode(int send_sync);
|
||||
char *redisGitSHA1(void);
|
||||
char *redisGitDirty(void);
|
||||
static int cliConnect(int flags);
|
||||
|
||||
static char *getInfoField(char *info, char *field);
|
||||
|
@ -424,20 +420,6 @@ typedef struct {
|
|||
static helpEntry *helpEntries = NULL;
|
||||
static int helpEntriesLen = 0;
|
||||
|
||||
static sds cliVersion(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;
|
||||
}
|
||||
|
||||
/* For backwards compatibility with pre-7.0 servers.
|
||||
* cliLegacyInitHelp() sets up the helpEntries array with the command and group
|
||||
* names from the commands.c file. However the Redis instance we are connecting
|
||||
|
|
15
src/server.c
15
src/server.c
|
@ -6250,15 +6250,16 @@ void daemonize(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void version(void) {
|
||||
printf("Redis server v=%s sha=%s:%d malloc=%s bits=%d build=%llx\n",
|
||||
sds getVersion(void) {
|
||||
sds version = sdscatprintf(sdsempty(),
|
||||
"v=%s sha=%s:%d malloc=%s bits=%d build=%llx",
|
||||
REDIS_VERSION,
|
||||
redisGitSHA1(),
|
||||
atoi(redisGitDirty()) > 0,
|
||||
ZMALLOC_LIB,
|
||||
sizeof(long) == 4 ? 32 : 64,
|
||||
(unsigned long long) redisBuildId());
|
||||
exit(0);
|
||||
return version;
|
||||
}
|
||||
|
||||
void usage(void) {
|
||||
|
@ -6992,7 +6993,13 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* Handle special options --help and --version */
|
||||
if (strcmp(argv[1], "-v") == 0 ||
|
||||
strcmp(argv[1], "--version") == 0) version();
|
||||
strcmp(argv[1], "--version") == 0)
|
||||
{
|
||||
sds version = getVersion();
|
||||
printf("Redis server %s\n", version);
|
||||
sdsfree(version);
|
||||
exit(0);
|
||||
}
|
||||
if (strcmp(argv[1], "--help") == 0 ||
|
||||
strcmp(argv[1], "-h") == 0) usage();
|
||||
if (strcmp(argv[1], "--test-memory") == 0) {
|
||||
|
|
|
@ -3789,6 +3789,7 @@ void killIOThreads(void);
|
|||
void killThreads(void);
|
||||
void makeThreadKillable(void);
|
||||
void swapMainDbWithTempDb(redisDb *tempDb);
|
||||
sds getVersion(void);
|
||||
|
||||
/* Use macro for checking log level to avoid evaluating arguments in cases log
|
||||
* should be ignored due to low level. */
|
||||
|
|
Loading…
Reference in New Issue