Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created May 10, 2013 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/5553300 to your computer and use it in GitHub Desktop.
Save kyanny/5553300 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
STDOUT.sync = true
require 'redis'
pid = spawn("redis-server", [:out, :err] => '/dev/null')
sleep 2
r = Redis.new
used_memory = r.info['used_memory'].to_i
maxmemory = used_memory + 1024*20 # 20kb
r.config(:set, 'maxmemory', maxmemory)
%w(volatile-lru volatile-ttl).each do |policy|
puts "==== maxmemory-policy = #{policy} ===="
r.config(:set, 'maxmemory-policy', policy)
[3, 676].each do |samples|
puts "==== maxmemory-samples = #{samples} ===="
r.config(:set, 'maxmemory-samples', samples)
10.times do |n|
r.flushall
puts "==== #{n} ===="
keys = ('a'..'z')
expires = 86400.step(0, -5)
keys.each do |k|
keys.each do |j|
expire = expires.next
key = "#{k}:#{j}:#{expire}"
value = '0' * 1024
r.setex(key, expire, value)
sleep 0.01
end
end
puts r.keys('*').sort
end
puts ""
end
puts ""
end
Process.kill(:INT, pid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment