Skip to content

Instantly share code, notes, and snippets.

@kapso
Created October 28, 2012 10:35
Show Gist options
  • Select an option

  • Save kapso/3968277 to your computer and use it in GitHub Desktop.

Select an option

Save kapso/3968277 to your computer and use it in GitHub Desktop.
Hiredis test
extend ActiveSupport::Benchmarkable
def logger; Rails.logger; end;
def redis_connection(hire = true)
hire ? Redis.new(logger: nil, driver: 'hiredis') : Redis.new(logger: nil)
end
def test_redis(size = 10_000, hire = true)
key = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0, 24]
data = {}
size.times do |i|
data[Digest::MD5.hexdigest((Time.now.to_i + i).to_s)[0, 24]] = rand(50)
end
redis = redis_connection(hire)
benchmark("Driver hiredis(#{hire}) - Time taken to SAVE hash size(#{data.size})".bright.color(:blue), level: :info) do
redis.mapped_hmset(key, data)
end
benchmark("Driver hiredis(#{hire}) - Time taken to FETCH hash size(#{data.size})".bright.color(:blue), level: :info) do
(result = redis.hkeys(key)).present?
end
logger.info "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment