Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
redis_memory_test example for key length comparision
def redis_memory_test
results = {}
redis = Redis.new
redis.flushdb
results[:clear] = redis.info(:memory)['used_memory'].to_i
(2..128).each do |i|
redis.pipelined do
10000.times { redis.incr( SecureRandom.urlsafe_base64( i ) ) }
end
results[i+1] = ((redis.info(:memory)['used_memory'].to_i - results[:clear]).to_f/1.megabyte).round(2)
redis.flushdb
end
# you need awesome-print gem to do this:
ap results
end
# some results:
# :clear => 724456,
# 3 => 0.55,
# 4 => 0.65,
# 5 => 0.58,
# 6 => 0.58,
# 7 => 0.74,
# ...
# 14 => 0.74,
# 15 => 0.8,
# 16 => 0.8,
# 17 => 0.8,
# 18 => 0.8,
# 19 => 0.95,
# 20 => 0.89,
...
# 30 => 0.89,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment