Skip to content

Instantly share code, notes, and snippets.

@loicginoux
Last active August 10, 2021 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loicginoux/24a44079101a02bd7a0c8647cf811b9b to your computer and use it in GitHub Desktop.
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)
# 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