教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 Redis RDB文件的解析工具梳理(rdr/redis-rdb-tools)

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

发布时间:2022-02-18   编辑:jiaochengji.com
教程集为您提供Redis RDB文件的解析工具梳理(rdr/redis-rdb-tools)等资源,欢迎您收藏本站,我们将为您提供最新的Redis RDB文件的解析工具梳理(rdr/redis-rdb-tools)资源
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"/></svg><h2>前言</h2>

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

<blockquote>

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

</blockquote> <blockquote>

https://github.com/xueqiu/rdr

</blockquote> <blockquote>

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).

</blockquote>

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

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

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

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

<h2>
rdr</h2> <h4>使用帮助</h4> <pre><code>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 </code></pre> <h4>简单说明</h4> <h5><code>./rdr dump dump.rdb</code></h5>

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

<pre><code>[ { "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 } } ] </code></pre>

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

<h5>
<code>./rdr show -p 8080 dump.rdb</code></h5>

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

<h5>
<code>./rdr keys dump.rdb</code></h5>

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

<h2>
redis-rdb-tools</h2> <pre><code>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 </code></pre>

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

到此这篇关于“Redis RDB文件的解析工具梳理(rdr/redis-rdb-tools)”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
Redis RDB文件的解析工具梳理(rdr/redis-rdb-tools)
统计Redis中各种数据的大小的例子
redis两种持久化方式-rdb快照以及aof日志
redis基础问答
REDIS基础, GO语言
超全的!Redis的安装和基础操作
Redis缓存之Set使用及redis遇到的一些问题
三分钟读懂redis数据库
配置 redis 主从复制一例
CentOS6.9源码编译安装redis和php-redis扩展

[关闭]
~ ~