Skip to content

Instantly share code, notes, and snippets.

@HenleyChiu
Created January 20, 2016 15:09
Show Gist options
  • Save HenleyChiu/25d7c9a6b854cafc7f0e to your computer and use it in GitHub Desktop.
Save HenleyChiu/25d7c9a6b854cafc7f0e to your computer and use it in GitHub Desktop.
save and get a large JSON string to redis
require "benchmark"
url = 'https://s3.amazonaws.com/buzzsumo-exports/test.json'
source = open(url).read
puts "# of bytes: #{source.size}"
redis = Redis.new(:host => "localhost", :port => 6379, :db => 0)
time = Benchmark.measure do
redis.set("cache_key", source)
end
puts "Time to save to redis: #{time}"
str = ""
time = Benchmark.measure do
str = redis.get("cache_key")
end
puts "Time to get from redis: #{time}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment