require 'em-synchrony'
require 'redis'
require 'redis/distributed'
require 'digest'
require 'redis/connection/synchrony'
EM.synchrony do
# this one fast
redis_hosts = ["redis://localhost:6379/1", "redis://localhost:6378/1"]
# this one slow
# redis_hosts = ["redis://redis-host1.com:6379/1", "redis://redis-host2.com:6379/1"]
r = Redis::Distributed.new(redis_hosts)
1000.times do |k|
key = ::Digest::MD5.hexdigest("f" + k.to_s)
100.times do |x|
r.sadd(key, ::Digest::MD5.hexdigest("f" + x.to_s)) {}
end
end
end