Skip to content

Instantly share code, notes, and snippets.

@slayer
Created October 6, 2023 11:38
Show Gist options
  • Save slayer/4a01e6191eff5a98e2c1f2a618ba2354 to your computer and use it in GitHub Desktop.
Save slayer/4a01e6191eff5a98e2c1f2a618ba2354 to your computer and use it in GitHub Desktop.
Get Redis database usage (per database)
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