Created
August 26, 2011 21:55
-
-
Save sanjayk/1174519 to your computer and use it in GitHub Desktop.
redis-rb, EventMachine::Synchrony::ConnectionPool and pipelined command
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 '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