Last active
August 10, 2021 13:13
-
-
Save loicginoux/24a44079101a02bd7a0c8647cf811b9b to your computer and use it in GitHub Desktop.
Get the REDIS keys size and print the ones taking more space (in ruby)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# store all keys with their memory value | |
keys_by_val = {} | |
keys = REDIS.keys('*').each do |key| | |
mem = REDIS.memory('usage', key) | |
keys_by_val[key] = mem | |
end | |
# order them by value | |
ordered = keys_by_val.sort_by { |k,v| v ? v : 0 } | |
# print the biggest keys | |
ordered.last(100).each do |oo| | |
p "key:#{oo.first} - memory used: #{oo.last / 1024} Kb" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment