Skip to content

Instantly share code, notes, and snippets.

@sanjayk
Created August 26, 2011 21:55
Show Gist options
  • Save sanjayk/1174519 to your computer and use it in GitHub Desktop.
Save sanjayk/1174519 to your computer and use it in GitHub Desktop.
redis-rb, EventMachine::Synchrony::ConnectionPool and pipelined command
require 'benchmark'
require 'redis/connection/synchrony'
require 'redis/connection/hiredis'
require 'redis'
redis = EventMachine::Synchrony::ConnectionPool.new(size: 1) do
Redis.new(:password => 'my password',
:host => 'my host',
:port => my port)
end
time = Benchmark.realtime {
redis.hincrby(:hash, :counter, 2);
redis.hset(:hash, :field, 'value');
}
puts "#{time*1000} milliseconds"
/*This code does not work*/
time = Benchmark.realtime {
redis.pipelined {
redis.hincrby(:hash, :counter, 2);
redis.hset(:hash, :field, 'value');
}
}
/*This code works*/
time = Benchmark.realtime {
redis.execute(false) do |redisX|
redisX.pipelined {
redisX.hgetall(:hash)
redisX.hincrby(:hash, :counter, 2);
redisX.hset(:hash, :field, 'value2');
}
end
}
puts "#{time*1000} milliseconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment