Created
December 12, 2015 18:50
-
-
Save rubyconvict/fa22d4829978fda963d9 to your computer and use it in GitHub Desktop.
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
#! /usr/bin/env ruby | |
require 'dotenv' | |
Dotenv.load | |
require 'redis' | |
# USAGE: | |
# Put credentials in .env file, wrapped in single quotes. DO NOT COMMMIT this file to git! | |
# Wrap values in single quotes and escape all quotes inside strings with \. | |
# bundle exec ruby script/dev/example_redis-rb.rb | |
puts ENV['REDIS_PASSWORD'] | |
puts 'Connecting...' | |
redis = Redis.new( | |
:host => ENV['REDIS_HOST'], | |
:port => ENV['REDIS_PORT'], | |
:password => ENV['REDIS_PASSWORD']) | |
# open a connection to Redis | |
puts 'Setting...' | |
key = 'foo' | |
redis.set(key, 'bar'); | |
value = redis.get(key); | |
puts "Setting expiry..." | |
redis.expire(key, 300) # seconds = 5 minutes. | |
puts "Response:" | |
puts value | |
# testing GET/SET/PING average is: <200 rps, <60ms | |
# 10 concurrent conn, if more: Error: Connection reset by peer | |
# redis-benchmark -h pub-redis-00000.eu-west-1-1.2.ec2.garantiadata.com -p 12386 -t ping,set,get -n 1000 -c 10 | |
# compare to localhost: ~2800 rps, 0 milliseconds | |
# redis-benchmark -t ping,set,get -n 1000 -c 10 | |
# no ssl :-( | |
# sudo tcpdump -nnvvXSs 1514 -n dst port 12386 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment