diff options
author | antirez <antirez@gmail.com> | 2014-04-14 08:59:13 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-04-16 15:09:46 +0200 |
commit | cf500998e85c54562aa8ecbca0d8c075b239be14 (patch) | |
tree | 0963a083e300b9bc8177cdcd9efc77bfdeec4424 | |
parent | 2c4a1eccda125d39aec41213efcbf15af9bccaaf (diff) | |
download | redis-cf500998e85c54562aa8ecbca0d8c075b239be14.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); } |