Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.