Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
005915b5
Commit
005915b5
authored
Dec 05, 2018
by
antirez
Browse files
RESP3: hiredis: map and set display for TTY output.
parent
24a05e39
Changes
1
Show whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
005915b5
...
...
@@ -820,8 +820,17 @@ static sds cliFormatReplyTTY(redisReply *r, char *prefix) {
out = sdscat(out,"(nil)\n");
break;
case REDIS_REPLY_ARRAY:
case REDIS_REPLY_MAP:
case REDIS_REPLY_SET:
if (r->elements == 0) {
out = sdscat(out,"(empty list or set)\n");
if (r->type == REDIS_REPLY_ARRAY)
out = sdscat(out,"(empty array)\n");
else if (r->type == REDIS_REPLY_MAP)
out = sdscat(out,"(empty hash)\n");
else if (r->type == REDIS_REPLY_SET)
out = sdscat(out,"(empty set)\n");
else
out = sdscat(out,"(empty aggregate type)\n");
} else {
unsigned int i, idxlen = 0;
char _prefixlen[16];
...
...
@@ -831,6 +840,7 @@ static sds cliFormatReplyTTY(redisReply *r, char *prefix) {
/* Calculate chars needed to represent the largest index */
i = r->elements;
if (r->type == REDIS_REPLY_MAP) i /= 2;
do {
idxlen++;
i /= 10;
...
...
@@ -842,17 +852,35 @@ static sds cliFormatReplyTTY(redisReply *r, char *prefix) {
_prefix = sdscat(sdsnew(prefix),_prefixlen);
/* Setup prefix format for every entry */
snprintf(_prefixfmt,sizeof(_prefixfmt),"%%s%%%ud) ",idxlen);
char numsep;
if (r->type == REDIS_REPLY_SET) numsep = '~';
else if (r->type == REDIS_REPLY_MAP) numsep = '#';
else numsep = ')';
snprintf(_prefixfmt,sizeof(_prefixfmt),"%%s%%%ud%c ",idxlen,numsep);
for (i = 0; i < r->elements; i++) {
unsigned int human_idx = (r->type == REDIS_REPLY_MAP) ?
i/2 : i;
human_idx++; /* Make it 1-based. */
/* Don't use the prefix for the first element, as the parent
* caller already prepended the index number. */
out = sdscatprintf(out,_prefixfmt,i == 0 ? "" : prefix,
i+1
);
out = sdscatprintf(out,_prefixfmt,i == 0 ? "" : prefix,
human_idx
);
/* Format the multi bulk entry */
tmp = cliFormatReplyTTY(r->element[i],_prefix);
out = sdscatlen(out,tmp,sdslen(tmp));
sdsfree(tmp);
/* For maps, format the value as well. */
if (r->type == REDIS_REPLY_MAP) {
i++;
sdsrange(out,0,-2);
out = sdscat(out," => ");
tmp = cliFormatReplyTTY(r->element[i],_prefix);
out = sdscatlen(out,tmp,sdslen(tmp));
sdsfree(tmp);
}
}
sdsfree(_prefix);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment