Redis RDB文件的解析工具梳理(rdr/redis-rdb-tools)

前言

目前关于Redis rdb文件解析的工具,目前了解到的主要有python写的 redis-rdb-tools 工具,和用golang写的 rdr 工具。

https://github.com/sripathikrishnan/redis-rdb-tools

https://github.com/xueqiu/rdr

RDR(redis data reveal) is a tool to parse redis rdbfile. Comparing to redis-rdb-tools, RDR is implemented by golang, much faster (5GB rdbfile takes about 2mins on my PC).

rdr这个工具的rdb解析是调用 https://github.com/dongmx/rdb这个库的代码,而这个库的代码是fork github.com/cupcake/rdb这个的,不过cupcake这个库好像从2016年就没有维护了。

而且cupcake也申明了This package was heavily inspired by redis-rdb-tools by Sripathi Krishnan.可见 redis-rdb-tools 还是真大佬啊。

不过rdr工具跟redis-rdb-tools工具相比,解析速度更快些,只是功能没有后者丰富。

关于这两个工具的安装,都可以参考这两个工具的github wiki,还是比较方便简单的。

rdr

使用帮助
NAME:
   rdr - a tool to parse redis rdbfile

USAGE:
   rdr [global options] command [command options] [arguments...]

VERSION:
   v0.0.1

COMMANDS:
     dump     dump statistical information of rdbfile to STDOUT
     show     show statistical information of rdbfile by webpage
     keys     get all keys from rdbfile
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version
简单说明
./rdr dump dump.rdb

解析dump.rdb文件,并输出如下内容:

[
{
    "CurrentInstance": "dump.rdb",
    "LargestKeyPrefixes": {
        "string": [
            {
                "Type": "string",
                "Key": "bbsabbsas",
                "Bytes": 80,
                "Num": 1
            }
        ]
    },
    "LargestKeys": [
        {
            "Key": "bbsabbsas",
            "Bytes": 80,
            "Type": "string",
            "NumOfElem": 8,
            "LenOfLargestElem": 0,
            "FieldOfLargestElem": ""
        }
    ],
    "LenLevelCount": {},
    "TotleBytes": 80,
    "TotleNum": 1,
    "TypeBytes": {
        "string": 80
    },
    "TypeNum": {
        "string": 1
    }
}
]

LargestKeyPrefixes 表示一类前缀的统计结果,LargestKeys 一般会输出前100个bigkey,还有整体的keys数量和占用bytes。

./rdr show -p 8080 dump.rdb

将dump.rdb文件解析后,通过http的8080端口展示在网页上,更方便解读。

./rdr keys dump.rdb

将dump.rdb文件中的key解析并输出(只有key,没有value)

redis-rdb-tools

usage: usage: rdb [options] /path/to/dump.rdb

Example : rdb --command json -k "user.*" /var/redis/6379/dump.rdb

positional arguments:
  dump_file             RDB Dump file to process

optional arguments:
  -h, --help            show this help message and exit
  -c CMD, --command CMD
                        Command to execute. Valid commands are json, diff,
                        justkeys, justkeyvals, memory and protocol
  -f FILE, --file FILE  Output file
  -n DBS, --db DBS      Database Number. Multiple databases can be provided.
                        If not specified, all databases will be included.
  -k KEYS, --key KEYS   Keys to export. This can be a regular expression
  -o NOT_KEYS, --not-key NOT_KEYS
                        Keys Not to export. This can be a regular expression
  -t TYPES, --type TYPES
                        Data types to include. Possible values are string,
                        hash, set, sortedset, list. Multiple typees can be
                        provided. If not specified, all data types will be
                        returned
  -b BYTES, --bytes BYTES
                        Limit memory output to keys greater to or equal to
                        this value (in bytes)
  -l LARGEST, --largest LARGEST
                        Limit memory output to only the top N keys (by size)
  -e {raw,print,utf8,base64}, --escape {raw,print,utf8,base64}
                        Escape strings to encoding: raw (default), print,
                        utf8, or base64.
  -x, --no-expire       With protocol command, remove expiry from all keys
  -a N, --amend-expire N
                        With protocol command, add N seconds to key expiry
                        time

这个工具的用法网上有比较多的说明,也比较全面,暂时不做赘述。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值