mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-02 11:59:17 -05:00
simple redis memory analysis script
This commit is contained in:
parent
63b5a6c4e0
commit
4b5354a99e
1 changed files with 28 additions and 0 deletions
28
script/redis_memory.rb
Normal file
28
script/redis_memory.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
require File.expand_path("../../config/environment", __FILE__)
|
||||||
|
|
||||||
|
@redis = $redis.without_namespace
|
||||||
|
|
||||||
|
stats = {}
|
||||||
|
|
||||||
|
@redis.scan_each do |k|
|
||||||
|
type = @redis.type k
|
||||||
|
debug = @redis.debug :object, k
|
||||||
|
len = debug.split("serializedlength:")[1].to_i
|
||||||
|
|
||||||
|
case type
|
||||||
|
when "zset"
|
||||||
|
elems = @redis.zcard k
|
||||||
|
when "list"
|
||||||
|
elems = @redis.llen k
|
||||||
|
when "hash"
|
||||||
|
elems = @redis.hlen k
|
||||||
|
end
|
||||||
|
|
||||||
|
stats[k] = [len, type, elems]
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Top 100 keys"
|
||||||
|
stats.sort{|a,b| b[1][0] <=> a[1][0]}.first(50).each do |k, (len, type, elems)|
|
||||||
|
elems = " [#{elems}]" if elems
|
||||||
|
puts "#{k} #{type} #{len}#{elems}"
|
||||||
|
end
|
Loading…
Reference in a new issue