Back

redis - 使用redis-audit 来分析redis的key的情况, 以及原生命令,查看redis的key的value的容量

发布时间: 2019-11-19 08:34:00

$ info keyspace 也可以看到, 某个redis 下有多少key 

0. 使用原生命令:

127.0.0.1:6xxx[1]> debug object klines:btcusdt:k:1
Value at:0x7fefbd2d86e0 refcount:1 encoding:quicklist serializedlength:1527872 lru:1914438 lru_seconds_idle:1 ql_nodes:515 ql_avg_node:158.58 ql_ziplist_max:-2 ql_compressed:0 ql_uncompressed_size:4198014

这里表示, serializedlength 1527872 单位是byte.  也就是压缩后1.5MB

参考:   https://github.com/snmaynard/redis-audit

1. git clone

2. bundle install 

3. 运行:  

bundle exec ruby redis-audit.rb -h 172.11.22.233 --port 6111 --dbnum 1

4. 就能看到各种结果了

/root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/redis-3.2.2/lib/redis/client.rb:441: warning: constant ::Fixnum is deprecated
Auditing 172.31.12.247:6800 dbnum:0 sampling 0 keys
Sampling 9 keys...
DB has 94 keys
Sampled 1.02 kB of Redis memory

Found 6 key groups

==============================================================================
Found 1 keys containing strings, like:
low_price_ethbtc

These keys use 8.77% of the total sampled memory (92 bytes)
None of these keys expire
Average last accessed time: 1 minutes, 12 seconds - (Max: 1 minutes, 12 seconds Min:1 minutes, 12 seconds)

==============================================================================
Found 1 keys containing strings, like:
peatio:eosbtc:ticker:open

These keys use 9.72% of the total sampled memory (102 bytes)
None of these keys expire
Average last accessed time: 6 seconds - (Max: 6 seconds Min:6 seconds)

==============================================================================
Found 1 keys containing strings, like:
yesterday_price_xrpbtc

These keys use 10.96% of the total sampled memory (115 bytes)
None of these keys expire
Average last accessed time: 2 minutes, 58 seconds - (Max: 2 minutes, 58 seconds Min:2 minutes, 58 seconds)

==============================================================================
Found 2 keys containing strings, like:
usd_price_cgw, usd_price_bch

These keys use 17.54% of the total sampled memory (184 bytes)
None of these keys expire
Average last accessed time: 9 seconds - (Max: 9 seconds Min:9 seconds)

==============================================================================
Found 1 keys containing strings, like:
account@member_id=9298@currency_id=110

These keys use 18.02% of the total sampled memory (189 bytes)
None of these keys expire
Average last accessed time: 2 days, 20 hours, 24 minutes, 58 seconds - (Max: 2 days, 20 hours, 24 minutes, 58 seconds Min:2 days, 20 hours, 24 minutes, 58 seconds)

==============================================================================
Found 3 keys containing strings, like:
24h_volume_dsctusdt, 24h_volume_eosbtc, 24h_volume_eoseth

These keys use 34.99% of the total sampled memory (367 bytes)
None of these keys expire
Average last accessed time: 59 seconds - (Max: 1 minutes, 12 seconds Min:42 seconds)

==============================================================================
Summary

---------------------------------------------------+--------------+-------------------+---------------------------------------------------
Key                                                | Memory Usage | Expiry Proportion | Last Access Time                                  
---------------------------------------------------+--------------+-------------------+---------------------------------------------------
24h_volume_dsctusdt                                | 34.99%       | 0.0%              | 42 seconds                                        
account@member_id=9298@currency_id=110             | 18.02%       | 0.0%              | 2 days, 20 hours, 24 minutes, 58 seconds          
usd_price_cgw                                      | 17.54%       | 0.0%              | 9 seconds                                         
yesterday_price_xrpbtc                             | 10.96%       | 0.0%              | 2 minutes, 58 seconds                             
peatio:eosbtc:ticker:open                          | 9.72%        | 0.0%              | 6 seconds                                         
low_price_ethbtc                                   | 8.77%        | 0.0%              | 1 minutes, 12 seconds                             
---------------------------------------------------+--------------+-------------------+---------------------------------------------------

Back