Skip to content

Commit

Permalink
Add to rdb-cli options --show-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
moticless committed Jul 18, 2024
1 parent 5e4f7a2 commit 989ecb5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ destruction, or when newer block replacing old one.
Usage: rdb-cli /path/to/dump.rdb [OPTIONS] {print|json|resp|redis} [FORMAT_OPTIONS]
OPTIONS:
-l, --log-file <PATH> Path to the log file or stdout (Default: './rdb-cli.log')
-s, --show-progress <INT> Show progress after every <INT> megabytes processed
-k, --key <REGEX> Include only keys that match REGEX
-K --no-key <REGEX> Exclude all keys that match REGEX
-t, --type <TYPE> Include only selected TYPE {str|list|set|zset|hash|module|func}
Expand Down
23 changes: 22 additions & 1 deletion src/cli/rdb-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ FILE* logfile = NULL;
/* common options to all FORMATTERS */
typedef struct Options {
const char *logfilePath;
int progressMb; /* print progress every <progressMb> MB. Set to 0 if disabled */
RdbRes (*formatFunc)(RdbParser *p, int argc, char **argv);
} Options;

Expand Down Expand Up @@ -100,6 +101,7 @@ static void printUsage(int shortUsage) {
printf("Usage: rdb-cli /path/to/dump.rdb [OPTIONS] {print|json|resp|redis} [FORMAT_OPTIONS]\n");
printf("OPTIONS:\n");
printf("\t-l, --log-file <PATH> Path to the log file or stdout (Default: './rdb-cli.log')\n");
printf("\t-s, --show-progress <INT> Show progress after every <INT> megabytes processed\n");
printf("\t-k, --key <REGEX> Include only keys that match REGEX\n");
printf("\t-K --no-key <REGEX> Exclude all keys that match REGEX\n");
printf("\t-t, --type <TYPE> Include only selected TYPE {str|list|set|zset|hash|module|func}\n");
Expand Down Expand Up @@ -350,6 +352,7 @@ int readCommonOptions(RdbParser *p, int argc, char* argv[], Options *options, in
int at;

/* default */
options->progressMb = 0;
options->logfilePath = LOG_FILE_PATH_DEF;
options->formatFunc = formatJson;

Expand All @@ -360,6 +363,9 @@ int readCommonOptions(RdbParser *p, int argc, char* argv[], Options *options, in
if (getOptArg(argc, argv, &at, "-l", "--log-file", NULL, &(options->logfilePath)))
continue;

if (getOptArgVal(argc, argv, &at, "-s", "--show-progress", NULL, &options->progressMb, 0, INT_MAX))
continue;

if (getOptArg(argc, argv, &at, "-k", "--key", NULL, &keyFilter)) {
if (applyFilters && (!RDBX_createHandlersFilterKey(p, keyFilter, 0)))
exit(1);
Expand Down Expand Up @@ -481,7 +487,22 @@ int main(int argc, char **argv)
/* now that the formatter got registered, attach filters */
readCommonOptions(parser, argc, argv, &options, 1);

while ((status = RDB_parse(parser)) == RDB_STATUS_WAIT_MORE_DATA);
/* If requested to print progress */
if (options.progressMb) {
RDB_setPauseInterval(parser, options.progressMb * 1024 * 1024);
while (1) {
status = RDB_parse(parser);
if (status == RDB_STATUS_WAIT_MORE_DATA)
continue;
else if (status == RDB_STATUS_PAUSED)
printf("... Processed %zuMBytes ...\n",
RDB_getBytesProcessed(parser) / (1024 * 1024));
else
break;
}
} else {
while ((status = RDB_parse(parser)) == RDB_STATUS_WAIT_MORE_DATA);
}

if (status != RDB_STATUS_OK)
return RDB_getErrorCode(parser);
Expand Down

0 comments on commit 989ecb5

Please sign in to comment.