Redis: Show database size/size for keys

前端 未结 9 1777
青春惊慌失措
青春惊慌失措 2020-12-12 11:26

My redis instance seems to being growing very large and I\'d like to find out which of the multiple databases I have in there consumes how much memory. Redis\' INFO

9条回答
  •  北海茫月
    2020-12-12 11:55

    Take a look at this project it outputs some interesting stats about keyspaces based on regexs and prefixes. It uses the DEBUG OBJECT command and scans the db, identifying groups of keys and estimating the percentage of space they're taking up.

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

    Output looks like this:

    Summary  
    
    ---------------------------------------------------+--------------+-------------------+---------------------------------------------------  
    Key                                                | Memory Usage | Expiry Proportion | Last Access Time                                    
    ---------------------------------------------------+--------------+-------------------+---------------------------------------------------  
    notification_3109439                               | 88.14%       | 0.0%              | 2 minutes                               
    user_profile_3897016                               | 11.86%       | 99.98%            | 20 seconds  
    ---------------------------------------------------+--------------+-------------------+---------------------------------------------------  
    

    Or this this one: https://github.com/sripathikrishnan/redis-rdb-tools which does a full analysis on the entire keyspace by analyzing a dump.rdb file offline. This one works well also. It can give you the avg/min/max size for the entries in your db, and will even do it based on a prefix.

提交回复
热议问题