Created
November 15, 2015 15:21
-
-
Save shilovk/50c9c30255196def6198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://github.com/logrusorgru/any/blob/master/redis_onlines_db_size/test.rb | |
require 'redis' | |
require 'benchmark' | |
# perfomance | |
require 'hiredis' | |
# `driver: :hiredis` for perfomance, `path: ""` too | |
$r = Redis.new driver: :hiredis, path: "/tmp/redis.sock" | |
count = 65000 | |
def decr_ip c | |
"255.255.#{(255255 - c).to_s.insert(3,".")}" | |
end | |
puts "Start with count: #{count}" | |
puts "Used memory: #{$r.info( :memory )["used_memory_human"]}" | |
# pipelined wrap for perfomance | |
$r.pipelined do | |
count.times do |i| | |
#$r.set "user:#{i}", nil | |
#$r.expire "user:#{i}", 10*60 | |
#$r.set "ip#{decr_ip(i)}", nil | |
#$r.expire "ip#{decr_ip(i)}", 10*60 | |
# rewrite for perfomance | |
$r.set "user:#{i}", nil, ex: 10*60 | |
$r.set "ip#{decr_ip(i)}", nil, ex: 10*60 | |
end | |
end | |
puts "stop" | |
puts "Used memory: #{$r.info( :memory )["used_memory_human"]}" | |
$r.flushdb | |
puts "flush" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment