diff options
author | antirez <antirez@gmail.com> | 2014-04-14 08:59:13 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-04-14 09:00:53 +0200 |
commit | f9dc3cb04d5fdca59bc2d92fe1bae586eb4a9a5b (patch) | |
tree | 620bc561eea0180eee850c8e2a3fe6b27e2af480 | |
parent | 261da523e860146066e052771e2217a84bc8d168 (diff) | |
download | redis-f9dc3cb04d5fdca59bc2d92fe1bae586eb4a9a5b.tar.gz |
PFDEBUG DECODE added.
Provides a human readable description of the opcodes composing a
run-length encoded HLL (sparse encoding).
The command is only useful for debugging / development tasks.
-rw-r--r-- | src/hyperloglog.c | 35 |
1 files changed, 35 insertions, 0 deletions
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 <key> */ + 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); } |