Created
October 6, 2023 11:38
-
-
Save slayer/4a01e6191eff5a98e2c1f2a618ba2354 to your computer and use it in GitHub Desktop.
Get Redis database usage (per database)
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
require 'redis' # gem install redis (4.8.x in my case) | |
15.times.each do |db| | |
redis = Redis.new(url: "redis://localhost/#{db}") # or whatever | |
total = 0 | |
redis.scan_each.each do |key| | |
size = redis.send(:send_command, [:memory, :usage, key]) | |
total += size | |
# puts " DB#{db} #{key} => #{size}b" | |
end | |
puts "DB#{db} total: #{total/1024/1024}M" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment