summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-12-05 12:22:37 +0100
committerantirez <antirez@gmail.com>2018-12-21 11:42:51 +0100
commitac03c3169253bbb069bfa0712480e9dcd0629898 (patch)
tree36881fb726436da70e7e2d448ac3c3d69c81322b
parent4084c46f43fba3028fa26c91b2962c1eec73a99d (diff)
downloadredis-ac03c3169253bbb069bfa0712480e9dcd0629898.tar.gz
RESP3: hiredis: map and set display for TTY output.
-rw-r--r--src/redis-cli.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index 6fe93e660..17063641c 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -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);
}