温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

redis-rdb-tools安装部署及使用

发布时间:2020-07-28 12:33:12 来源:网络 阅读:29502 作者:苏黎世1995 栏目:关系型数据库

redis内存分析工具redis-rdb-tools安装部署
项目地址:https://github.com/sripathikrishnan/redis-rdb-tools


安装部署
安装Python2.7
下载redis-rdb-tools
git clone https://github.com/sripathikrishnan/redis-rdb-tools.git
安装redis-rdb-tools
pip2.7 install  python-lzf
cd redis-rdb-tools
python2.7 setup.py install
常见用法:
# 以json格式输出
> rdb --command json /var/redis/6379/dump.rdb

# 以json格式输出,模糊查找
> rdb --command justkeyvals --key "user.*" /var/redis/6379/dump.rdb

user003 fname Ron,sname Bumquist,
user001 fname Raoul,sname Duke,
user002 fname Gonzo,sname Dr,
user_list user003,user002,user001

# 查找确定键信息
> redis-memory-for-key -s localhost -p 6379 -a mypassword person:1

Key             person:1
Bytes               111
Type                hash
Encoding            ziplist
Number of Elements      2
Length of Largest Element   8

# rdb文件解析并输出为csv
> rdb -c memory /var/redis/6379/dump.rdb --bytes 128 -f memory.csv
> cat memory.csv

database,type,key,size_in_bytes,encoding,num_elements,len_largest_element
0,list,lizards,241,quicklist,5,19
0,list,user_list,190,quicklist,3,7
2,hash,baloon,138,ziplist,3,11
2,list,armadillo,231,quicklist,5,20
2,hash,aroma,129,ziplist,3,11

#  输出top10的键信息
rdb -c memory  --largest=10  /app/redis/data/7000/dump.rdb
报错及解决方法:

在redis-cluster模式下使用户出现如下报错,将地址改为该键对应的地址即可

[root@TEST python2.7]# redis-memory-for-key -s 172.16.2.53 -p 7000 KEYNAMETEST
Traceback (most recent call last):
  File "/usr/local/python2.7/bin/redis-memory-for-key", line 11, in <module>
    load_entry_point('rdbtools==0.1.12', 'console_scripts', 'redis-memory-for-key')()
  File "/usr/local/python2.7/lib/python2.7/site-packages/rdbtools-0.1.12-py2.7.egg/rdbtools/cli/redis_memory_for_key.py", line 43, in main
    db=options.db, password=options.password)
  File "/usr/local/python2.7/lib/python2.7/site-packages/rdbtools-0.1.12-py2.7.egg/rdbtools/cli/redis_memory_for_key.py", line 53, in print_memory_for_key
    raw_dump = redis.execute_command('dump', key)
  File "/usr/local/python2.7/lib/python2.7/site-packages/redis/client.py", line 668, in execute_command
    return self.parse_response(connection, command_name, **options)
  File "/usr/local/python2.7/lib/python2.7/site-packages/redis/client.py", line 680, in parse_response
    response = connection.read_response()
  File "/usr/local/python2.7/lib/python2.7/site-packages/redis/connection.py", line 629, in read_response
    raise response
redis.exceptions.ResponseError: MOVED 16278 172.16.0.99:7000
[root@TEST python2.7]# redis-memory-for-key -s 172.16.0.99 -p 7000 KEYNAMETEST
Key             KEYNAMETEST
Bytes               933972.0
Type                sortedset
Encoding            skiplist
Number of Elements      7658
Length of Largest Element   8

注意事项:

1、整个rdb文件的解析会导致CPU占用严重,所以慎用!!!
2、最好选择单键查询的方式,不太消耗资源
3、如果需要解析某个rdb文件,最好使用它的备份文件,或者将文件导出到本地或者测试机进行解析
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI