Skip to content

Instantly share code, notes, and snippets.

@jtoy
Created December 19, 2011 00:00
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 jtoy/1494874 to your computer and use it in GitHub Desktop.
Save jtoy/1494874 to your computer and use it in GitHub Desktop.
kill em / redis / bloomfilter
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