diff --git a/src/hyperloglog.c b/src/hyperloglog.c index f99d188f8..9f1827033 100644 --- a/src/hyperloglog.c +++ b/src/hyperloglog.c @@ -1243,6 +1243,41 @@ void pfdebugCommand(redisClient *c) { HLL_DENSE_GET_REGISTER(val,hdr->registers,j); addReplyLongLong(c,val); } + } + /* PFDEBUG DECODE */ + else if (!strcasecmp(cmd,"decode")) { + if (c->argc != 3) goto arityerr; + + uint8_t *p = o->ptr, *end = p+sdslen(o->ptr); + sds decoded = sdsempty(); + + if (hdr->encoding != HLL_SPARSE) { + addReplyError(c,"HLL encoding is not sparse"); + return; + } + + p += HLL_HDR_SIZE; + while(p < end) { + int runlen, regval; + + if (HLL_SPARSE_IS_ZERO(p)) { + runlen = HLL_SPARSE_ZERO_LEN(p); + p++; + decoded = sdscatprintf(decoded,"z:%d ",runlen); + } else if (HLL_SPARSE_IS_XZERO(p)) { + runlen = HLL_SPARSE_XZERO_LEN(p); + p += 2; + decoded = sdscatprintf(decoded,"Z:%d ",runlen); + } else { + runlen = HLL_SPARSE_VAL_LEN(p); + regval = HLL_SPARSE_VAL_VALUE(p); + p++; + decoded = sdscatprintf(decoded,"v:%d,%d ",regval,runlen); + } + } + decoded = sdstrim(decoded," "); + addReplyBulkCBuffer(c,decoded,sdslen(decoded)); + sdsfree(decoded); } else { addReplyErrorFormat(c,"Unknown PFDEBUG subcommand '%s'", cmd); }