Created
December 19, 2011 00:00
-
-
Save jtoy/1494874 to your computer and use it in GitHub Desktop.
kill em / redis / bloomfilter
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
require 'redis' | |
require 'redis/connection/synchrony' | |
require "em-synchrony/fiber_iterator" | |
require 'bloomfilter-rb' | |
max = 10_000 | |
EM.synchrony do | |
LBF = BloomFilter::Redis.new(:size => max, :hashes => 2, :seed => 1,:namespace => "test") | |
process_queue = lambda do | |
Fiber.new{ | |
array = [] | |
max.times.each{ array << rand(max)} | |
EM::Synchrony::FiberIterator.new(array).each do |x| | |
in_bf = LBF.include?(x) | |
puts "#{x} in bm #{in_bf}" | |
LBF.insert(x) unless in_bf | |
end | |
array = nil | |
EM.next_tick { process_queue.call } | |
}.resume | |
end | |
EM.add_periodic_timer(1){ process_queue.call } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment