1.redis-rdb-tools安装
1.1 更新python-lzf依赖包
pip install rdbtools python-lzf
1.2 安装redis-rdb-tools
git clone https://github.com/sripathikrishnan/redis-rdb-tools
cd redis-rdb-tools
python3 setup.py install
注意:rdb使用依赖于python3,所以直接需要将python的软链接由python2转成python3
安装完毕之后,先查看下是否能够正常使用
1.3 源码zip包安装
wget https://github.com/sripathikrishnan/redis-rdb-tools/archive/master.zip
unzip master.zip
cd redis-rdb-tools-master/
python3 setup.py install
rm -f /usr/bin/python
ln -s /usr/bin/python3 /usr/bin/python
2.命令行用法示例
2.1 rdb 使用方法
[root@redis_zxb1 bin]# rdb --help
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
2.2??redis-memory-for-key 使用方法,主要用于单个keys的内存消耗
[root@redis_zxb1 bin]# redis-memory-for-key --help
Usage: redis-memory-for-key [options] redis-key
Examples :
redis-memory-for-key user:13423
redis-memory-for-key -s localhost -p 6379 user:13423
Options:
-h, --help show this help message and exit
-s HOST, --server=HOST
Redis Server hostname. Defaults to 127.0.0.1
-p PORT, --port=PORT Redis Server port. Defaults to 6379
-a PASSWORD, --password=PASSWORD
Password to use when connecting to the server
-d DB, --db=DB Database number, defaults to 0
2.3 redis-profiler的使用方法
[root@redis_zxb1 bin]# redis-profiler --help
Usage: redis-profiler [options] /path/to/dump.rdb
Example 1 : redis-profiler -k "user.*" -k "friends.*" -f memoryreport.html /var/redis/6379/dump.rdb
Example 2 : redis-profiler /var/redis/6379/dump.rdb
Options:
-h, --help show this help message and exit
-f FILE, --file=FILE Output file
-k KEYS, --key=KEYS Keys that should be grouped together. Multiple regexes
can be provided
3.参考:
Redis RDB 分析工具 rdbtools 说明 - jyzhou - 博客园
|