Skip to content

Instantly share code, notes, and snippets.

@alekseyl
Last active May 14, 2018 07:27
Show Gist options
  • Save alekseyl/06abe3417d1572a7f880c347358874cc to your computer and use it in GitHub Desktop.
Save alekseyl/06abe3417d1572a7f880c347358874cc to your computer and use it in GitHub Desktop.
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