redis 3.3.5 → 4.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +132 -2
- data/README.md +144 -79
- data/lib/redis.rb +1174 -405
- data/lib/redis/client.rb +150 -90
- data/lib/redis/cluster.rb +295 -0
- data/lib/redis/cluster/command.rb +81 -0
- data/lib/redis/cluster/command_loader.rb +34 -0
- data/lib/redis/cluster/key_slot_converter.rb +72 -0
- data/lib/redis/cluster/node.rb +107 -0
- data/lib/redis/cluster/node_key.rb +31 -0
- data/lib/redis/cluster/node_loader.rb +37 -0
- data/lib/redis/cluster/option.rb +93 -0
- data/lib/redis/cluster/slot.rb +86 -0
- data/lib/redis/cluster/slot_loader.rb +49 -0
- data/lib/redis/connection.rb +4 -2
- data/lib/redis/connection/command_helper.rb +5 -10
- data/lib/redis/connection/hiredis.rb +6 -5
- data/lib/redis/connection/registry.rb +2 -1
- data/lib/redis/connection/ruby.rb +126 -128
- data/lib/redis/connection/synchrony.rb +21 -8
- data/lib/redis/distributed.rb +147 -72
- data/lib/redis/errors.rb +48 -0
- data/lib/redis/hash_ring.rb +30 -73
- data/lib/redis/pipeline.rb +55 -15
- data/lib/redis/subscribe.rb +11 -12
- data/lib/redis/version.rb +3 -1
- metadata +49 -202
- data/.gitignore +0 -16
- data/.travis.yml +0 -89
- data/.travis/Gemfile +0 -11
- data/.yardopts +0 -3
- data/Gemfile +0 -4
- data/Rakefile +0 -87
- data/benchmarking/logging.rb +0 -71
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/examples/basic.rb +0 -15
- data/examples/consistency.rb +0 -114
- data/examples/dist_redis.rb +0 -43
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -37
- data/examples/sentinel.rb +0 -41
- data/examples/sentinel/sentinel.conf +0 -9
- data/examples/sentinel/start +0 -49
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/redis.gemspec +0 -44
- data/test/bitpos_test.rb +0 -69
- data/test/blocking_commands_test.rb +0 -42
- data/test/client_test.rb +0 -59
- data/test/command_map_test.rb +0 -30
- data/test/commands_on_hashes_test.rb +0 -21
- data/test/commands_on_hyper_log_log_test.rb +0 -21
- data/test/commands_on_lists_test.rb +0 -20
- data/test/commands_on_sets_test.rb +0 -77
- data/test/commands_on_sorted_sets_test.rb +0 -137
- data/test/commands_on_strings_test.rb +0 -101
- data/test/commands_on_value_types_test.rb +0 -133
- data/test/connection_handling_test.rb +0 -277
- data/test/connection_test.rb +0 -57
- data/test/db/.gitkeep +0 -0
- data/test/distributed_blocking_commands_test.rb +0 -46
- data/test/distributed_commands_on_hashes_test.rb +0 -10
- data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
- data/test/distributed_commands_on_lists_test.rb +0 -22
- data/test/distributed_commands_on_sets_test.rb +0 -83
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
- data/test/distributed_commands_on_strings_test.rb +0 -59
- data/test/distributed_commands_on_value_types_test.rb +0 -95
- data/test/distributed_commands_requiring_clustering_test.rb +0 -164
- data/test/distributed_connection_handling_test.rb +0 -23
- data/test/distributed_internals_test.rb +0 -79
- data/test/distributed_key_tags_test.rb +0 -52
- data/test/distributed_persistence_control_commands_test.rb +0 -26
- data/test/distributed_publish_subscribe_test.rb +0 -92
- data/test/distributed_remote_server_control_commands_test.rb +0 -66
- data/test/distributed_scripting_test.rb +0 -102
- data/test/distributed_sorting_test.rb +0 -20
- data/test/distributed_test.rb +0 -58
- data/test/distributed_transactions_test.rb +0 -32
- data/test/encoding_test.rb +0 -18
- data/test/error_replies_test.rb +0 -59
- data/test/fork_safety_test.rb +0 -65
- data/test/helper.rb +0 -232
- data/test/helper_test.rb +0 -24
- data/test/internals_test.rb +0 -417
- data/test/lint/blocking_commands.rb +0 -150
- data/test/lint/hashes.rb +0 -162
- data/test/lint/hyper_log_log.rb +0 -60
- data/test/lint/lists.rb +0 -143
- data/test/lint/sets.rb +0 -140
- data/test/lint/sorted_sets.rb +0 -316
- data/test/lint/strings.rb +0 -260
- data/test/lint/value_types.rb +0 -122
- data/test/persistence_control_commands_test.rb +0 -26
- data/test/pipelining_commands_test.rb +0 -242
- data/test/publish_subscribe_test.rb +0 -282
- data/test/remote_server_control_commands_test.rb +0 -118
- data/test/scanning_test.rb +0 -413
- data/test/scripting_test.rb +0 -78
- data/test/sentinel_command_test.rb +0 -80
- data/test/sentinel_test.rb +0 -255
- data/test/sorting_test.rb +0 -59
- data/test/ssl_test.rb +0 -73
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -130
- data/test/support/ssl/gen_certs.sh +0 -31
- data/test/support/ssl/trusted-ca.crt +0 -25
- data/test/support/ssl/trusted-ca.key +0 -27
- data/test/support/ssl/trusted-cert.crt +0 -81
- data/test/support/ssl/trusted-cert.key +0 -28
- data/test/support/ssl/untrusted-ca.crt +0 -26
- data/test/support/ssl/untrusted-ca.key +0 -27
- data/test/support/ssl/untrusted-cert.crt +0 -82
- data/test/support/ssl/untrusted-cert.key +0 -28
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -88
- data/test/test.conf.erb +0 -9
- data/test/thread_safety_test.rb +0 -62
- data/test/transactions_test.rb +0 -264
- data/test/unknown_commands_test.rb +0 -14
- data/test/url_param_test.rb +0 -138
data/.gitignore
DELETED
data/.travis.yml
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
rvm:
|
4
|
-
- 1.8.7
|
5
|
-
- 1.9.3
|
6
|
-
- 2.0
|
7
|
-
- 2.1
|
8
|
-
- 2.2
|
9
|
-
- 2.3.0
|
10
|
-
- jruby-18mode
|
11
|
-
- jruby-19mode
|
12
|
-
- jruby-9.0.5.0
|
13
|
-
- rbx-2
|
14
|
-
|
15
|
-
gemfile: ".travis/Gemfile"
|
16
|
-
|
17
|
-
sudo: false
|
18
|
-
|
19
|
-
env:
|
20
|
-
global:
|
21
|
-
- VERBOSE=true
|
22
|
-
- TIMEOUT=1
|
23
|
-
matrix:
|
24
|
-
- conn=ruby REDIS_BRANCH=3.0
|
25
|
-
- conn=ruby REDIS_BRANCH=3.2
|
26
|
-
- conn=hiredis REDIS_BRANCH=3.0
|
27
|
-
- conn=hiredis REDIS_BRANCH=3.2
|
28
|
-
- conn=synchrony REDIS_BRANCH=3.0
|
29
|
-
- conn=synchrony REDIS_BRANCH=3.2
|
30
|
-
- conn=ruby REDIS_BRANCH=unstable
|
31
|
-
|
32
|
-
branches:
|
33
|
-
only:
|
34
|
-
- master
|
35
|
-
|
36
|
-
matrix:
|
37
|
-
exclude:
|
38
|
-
# hiredis
|
39
|
-
- rvm: jruby-18mode
|
40
|
-
gemfile: .travis/Gemfile
|
41
|
-
env: conn=hiredis REDIS_BRANCH=3.0
|
42
|
-
- rvm: jruby-18mode
|
43
|
-
gemfile: .travis/Gemfile
|
44
|
-
env: conn=hiredis REDIS_BRANCH=3.2
|
45
|
-
- rvm: jruby-19mode
|
46
|
-
gemfile: .travis/Gemfile
|
47
|
-
env: conn=hiredis REDIS_BRANCH=3.0
|
48
|
-
- rvm: jruby-19mode
|
49
|
-
gemfile: .travis/Gemfile
|
50
|
-
env: conn=hiredis REDIS_BRANCH=3.2
|
51
|
-
- rvm: jruby-9.0.5.0
|
52
|
-
gemfile: .travis/Gemfile
|
53
|
-
env: conn=hiredis REDIS_BRANCH=3.0
|
54
|
-
- rvm: jruby-9.0.5.0
|
55
|
-
gemfile: .travis/Gemfile
|
56
|
-
env: conn=hiredis REDIS_BRANCH=3.2
|
57
|
-
|
58
|
-
# synchrony
|
59
|
-
- rvm: 1.8.7
|
60
|
-
gemfile: .travis/Gemfile
|
61
|
-
env: conn=synchrony REDIS_BRANCH=3.0
|
62
|
-
- rvm: 1.8.7
|
63
|
-
gemfile: .travis/Gemfile
|
64
|
-
env: conn=synchrony REDIS_BRANCH=3.2
|
65
|
-
- rvm: jruby-18mode
|
66
|
-
gemfile: .travis/Gemfile
|
67
|
-
env: conn=synchrony REDIS_BRANCH=3.0
|
68
|
-
- rvm: jruby-18mode
|
69
|
-
gemfile: .travis/Gemfile
|
70
|
-
env: conn=synchrony REDIS_BRANCH=3.2
|
71
|
-
- rvm: jruby-19mode
|
72
|
-
gemfile: .travis/Gemfile
|
73
|
-
env: conn=synchrony REDIS_BRANCH=3.0
|
74
|
-
- rvm: jruby-19mode
|
75
|
-
gemfile: .travis/Gemfile
|
76
|
-
env: conn=synchrony REDIS_BRANCH=3.2
|
77
|
-
- rvm: jruby-9.0.5.0
|
78
|
-
gemfile: .travis/Gemfile
|
79
|
-
env: conn=synchrony REDIS_BRANCH=3.0
|
80
|
-
- rvm: jruby-9.0.5.0
|
81
|
-
gemfile: .travis/Gemfile
|
82
|
-
env: conn=synchrony REDIS_BRANCH=3.2
|
83
|
-
allow_failures:
|
84
|
-
- rvm: rbx-2
|
85
|
-
|
86
|
-
notifications:
|
87
|
-
irc:
|
88
|
-
- irc.freenode.net#redis-rb
|
89
|
-
email: false
|
data/.travis/Gemfile
DELETED
data/.yardopts
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
require "rake/testtask"
|
2
|
-
|
3
|
-
ENV["REDIS_BRANCH"] ||= "unstable"
|
4
|
-
|
5
|
-
REDIS_DIR = File.expand_path(File.join("..", "test"), __FILE__)
|
6
|
-
REDIS_CNF = File.join(REDIS_DIR, "test.conf")
|
7
|
-
REDIS_CNF_TEMPLATE = File.join(REDIS_DIR, "test.conf.erb")
|
8
|
-
REDIS_PID = File.join(REDIS_DIR, "db", "redis.pid")
|
9
|
-
REDIS_LOG = File.join(REDIS_DIR, "db", "redis.log")
|
10
|
-
REDIS_SOCKET = File.join(REDIS_DIR, "db", "redis.sock")
|
11
|
-
BINARY = "tmp/redis-#{ENV["REDIS_BRANCH"]}/src/redis-server"
|
12
|
-
|
13
|
-
task :default => :run
|
14
|
-
|
15
|
-
desc "Run tests and manage server start/stop"
|
16
|
-
task :run => [:start, :test, :stop]
|
17
|
-
|
18
|
-
desc "Start the Redis server"
|
19
|
-
task :start => [BINARY, REDIS_CNF] do
|
20
|
-
sh "#{BINARY} --version"
|
21
|
-
|
22
|
-
redis_running = \
|
23
|
-
begin
|
24
|
-
File.exists?(REDIS_PID) && Process.kill(0, File.read(REDIS_PID).to_i)
|
25
|
-
rescue Errno::ESRCH
|
26
|
-
FileUtils.rm REDIS_PID
|
27
|
-
false
|
28
|
-
end
|
29
|
-
|
30
|
-
unless redis_running
|
31
|
-
unless system("#{BINARY} #{REDIS_CNF}")
|
32
|
-
abort "could not start redis-server"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
at_exit do
|
37
|
-
Rake::Task["stop"].invoke
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
desc "Stop the Redis server"
|
42
|
-
task :stop do
|
43
|
-
if File.exists?(REDIS_PID)
|
44
|
-
Process.kill "INT", File.read(REDIS_PID).to_i
|
45
|
-
FileUtils.rm REDIS_PID
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
desc "Clean up testing artifacts"
|
50
|
-
task :clean do
|
51
|
-
FileUtils.rm_f(BINARY)
|
52
|
-
FileUtils.rm_f(REDIS_CNF)
|
53
|
-
end
|
54
|
-
|
55
|
-
file BINARY do
|
56
|
-
branch = ENV.fetch("REDIS_BRANCH")
|
57
|
-
|
58
|
-
sh <<-SH
|
59
|
-
mkdir -p tmp;
|
60
|
-
cd tmp;
|
61
|
-
rm -rf redis-#{branch};
|
62
|
-
wget https://github.com/antirez/redis/archive/#{branch}.tar.gz -O #{branch}.tar.gz;
|
63
|
-
tar xf #{branch}.tar.gz;
|
64
|
-
cd redis-#{branch};
|
65
|
-
make
|
66
|
-
SH
|
67
|
-
end
|
68
|
-
|
69
|
-
file REDIS_CNF => [REDIS_CNF_TEMPLATE, __FILE__] do |t|
|
70
|
-
require 'erb'
|
71
|
-
|
72
|
-
erb = t.prerequisites[0]
|
73
|
-
template = File.read(erb)
|
74
|
-
|
75
|
-
File.open(REDIS_CNF, 'w') do |file|
|
76
|
-
file.puts "\# This file was auto-generated at #{Time.now}",
|
77
|
-
"\# from (#{erb})",
|
78
|
-
"\#"
|
79
|
-
conf = ERB.new(template).result
|
80
|
-
file << conf
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
Rake::TestTask.new do |t|
|
85
|
-
t.options = "-v" if $VERBOSE
|
86
|
-
t.test_files = FileList["test/*_test.rb"]
|
87
|
-
end
|
data/benchmarking/logging.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# Run with
|
2
|
-
#
|
3
|
-
# $ ruby -Ilib benchmarking/logging.rb
|
4
|
-
#
|
5
|
-
|
6
|
-
begin
|
7
|
-
require "bench"
|
8
|
-
rescue LoadError
|
9
|
-
$stderr.puts "`gem install bench` and try again."
|
10
|
-
exit 1
|
11
|
-
end
|
12
|
-
|
13
|
-
require "redis"
|
14
|
-
require "logger"
|
15
|
-
|
16
|
-
def log(level, namespace = nil)
|
17
|
-
logger = (namespace || Kernel).const_get(:Logger).new("/dev/null")
|
18
|
-
logger.level = (namespace || Logger).const_get(level)
|
19
|
-
logger
|
20
|
-
end
|
21
|
-
|
22
|
-
def stress(redis)
|
23
|
-
redis.flushdb
|
24
|
-
|
25
|
-
n = (ARGV.shift || 2000).to_i
|
26
|
-
|
27
|
-
n.times do |i|
|
28
|
-
key = "foo:#{i}"
|
29
|
-
redis.set key, i
|
30
|
-
redis.get key
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
default = Redis.new
|
35
|
-
|
36
|
-
logging_redises = [
|
37
|
-
Redis.new(:logger => log(:DEBUG)),
|
38
|
-
Redis.new(:logger => log(:INFO)),
|
39
|
-
]
|
40
|
-
|
41
|
-
begin
|
42
|
-
require "log4r"
|
43
|
-
|
44
|
-
logging_redises += [
|
45
|
-
Redis.new(:logger => log(:DEBUG, Log4r)),
|
46
|
-
Redis.new(:logger => log(:INFO, Log4r)),
|
47
|
-
]
|
48
|
-
rescue LoadError
|
49
|
-
$stderr.puts "Log4r not installed. `gem install log4r` if you want to compare it against Ruby's Logger (spoiler: it's much faster)."
|
50
|
-
end
|
51
|
-
|
52
|
-
benchmark "Default options (no logger)" do
|
53
|
-
stress(default)
|
54
|
-
end
|
55
|
-
|
56
|
-
logging_redises.each do |redis|
|
57
|
-
logger = redis.client.logger
|
58
|
-
|
59
|
-
case logger
|
60
|
-
when Logger
|
61
|
-
level = Logger::SEV_LABEL[logger.level]
|
62
|
-
when Log4r::Logger
|
63
|
-
level = logger.levels[logger.level]
|
64
|
-
end
|
65
|
-
|
66
|
-
benchmark "#{logger.class} on #{level}" do
|
67
|
-
stress(redis)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
run 10
|
data/benchmarking/pipeline.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require "benchmark"
|
2
|
-
|
3
|
-
$:.push File.join(File.dirname(__FILE__), 'lib')
|
4
|
-
|
5
|
-
require 'redis'
|
6
|
-
|
7
|
-
ITERATIONS = 10000
|
8
|
-
|
9
|
-
@r = Redis.new
|
10
|
-
|
11
|
-
Benchmark.bmbm do |benchmark|
|
12
|
-
benchmark.report("set") do
|
13
|
-
@r.flushdb
|
14
|
-
|
15
|
-
ITERATIONS.times do |i|
|
16
|
-
@r.set("foo#{i}", "Hello world!")
|
17
|
-
@r.get("foo#{i}")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
benchmark.report("set (pipelined)") do
|
22
|
-
@r.flushdb
|
23
|
-
|
24
|
-
@r.pipelined do
|
25
|
-
ITERATIONS.times do |i|
|
26
|
-
@r.set("foo#{i}", "Hello world!")
|
27
|
-
@r.get("foo#{i}")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
benchmark.report("lpush+ltrim") do
|
33
|
-
@r.flushdb
|
34
|
-
|
35
|
-
ITERATIONS.times do |i|
|
36
|
-
@r.lpush "lpush#{i}", i
|
37
|
-
@r.ltrim "ltrim#{i}", 0, 30
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
benchmark.report("lpush+ltrim (pipelined)") do
|
42
|
-
@r.flushdb
|
43
|
-
|
44
|
-
@r.pipelined do
|
45
|
-
ITERATIONS.times do |i|
|
46
|
-
@r.lpush "lpush#{i}", i
|
47
|
-
@r.ltrim "ltrim#{i}", 0, 30
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/benchmarking/speed.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# Run with
|
2
|
-
#
|
3
|
-
# $ ruby -Ilib benchmarking/speed.rb
|
4
|
-
#
|
5
|
-
|
6
|
-
require "benchmark"
|
7
|
-
require "redis"
|
8
|
-
|
9
|
-
r = Redis.new
|
10
|
-
n = (ARGV.shift || 20000).to_i
|
11
|
-
|
12
|
-
elapsed = Benchmark.realtime do
|
13
|
-
# n sets, n gets
|
14
|
-
n.times do |i|
|
15
|
-
key = "foo#{i}"
|
16
|
-
r[key] = key * 10
|
17
|
-
r[key]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
puts '%.2f Kops' % (2 * n / 1000 / elapsed)
|
data/benchmarking/suite.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
def run_in_background(command)
|
4
|
-
fork { system command }
|
5
|
-
end
|
6
|
-
|
7
|
-
def with_all_segments(&block)
|
8
|
-
0.upto(9) do |segment_number|
|
9
|
-
block_size = 100000
|
10
|
-
start_index = segment_number * block_size
|
11
|
-
end_index = start_index + block_size - 1
|
12
|
-
block.call(start_index, end_index)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
#with_all_segments do |start_index, end_index|
|
17
|
-
# puts "Initializing keys from #{start_index} to #{end_index}"
|
18
|
-
# system "ruby worker.rb initialize #{start_index} #{end_index} 0"
|
19
|
-
#end
|
20
|
-
|
21
|
-
with_all_segments do |start_index, end_index|
|
22
|
-
run_in_background "ruby worker.rb write #{start_index} #{end_index} 10"
|
23
|
-
run_in_background "ruby worker.rb read #{start_index} #{end_index} 1"
|
24
|
-
end
|
data/benchmarking/worker.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
BENCHMARK_ROOT = File.dirname(__FILE__)
|
2
|
-
REDIS_ROOT = File.join(BENCHMARK_ROOT, "..", "lib")
|
3
|
-
|
4
|
-
$: << REDIS_ROOT
|
5
|
-
require 'redis'
|
6
|
-
require 'benchmark'
|
7
|
-
|
8
|
-
def show_usage
|
9
|
-
puts <<-EOL
|
10
|
-
Usage: worker.rb [read:write] <start_index> <end_index> <sleep_msec>
|
11
|
-
EOL
|
12
|
-
end
|
13
|
-
|
14
|
-
def shift_from_argv
|
15
|
-
value = ARGV.shift
|
16
|
-
unless value
|
17
|
-
show_usage
|
18
|
-
exit -1
|
19
|
-
end
|
20
|
-
value
|
21
|
-
end
|
22
|
-
|
23
|
-
operation = shift_from_argv.to_sym
|
24
|
-
start_index = shift_from_argv.to_i
|
25
|
-
end_index = shift_from_argv.to_i
|
26
|
-
sleep_msec = shift_from_argv.to_i
|
27
|
-
sleep_duration = sleep_msec/1000.0
|
28
|
-
|
29
|
-
redis = Redis.new
|
30
|
-
|
31
|
-
case operation
|
32
|
-
when :initialize
|
33
|
-
|
34
|
-
start_index.upto(end_index) do |i|
|
35
|
-
redis[i] = 0
|
36
|
-
end
|
37
|
-
|
38
|
-
when :clear
|
39
|
-
|
40
|
-
start_index.upto(end_index) do |i|
|
41
|
-
redis.delete(i)
|
42
|
-
end
|
43
|
-
|
44
|
-
when :read, :write
|
45
|
-
|
46
|
-
puts "Starting to #{operation} at segment #{end_index + 1}"
|
47
|
-
|
48
|
-
loop do
|
49
|
-
t1 = Time.now
|
50
|
-
start_index.upto(end_index) do |i|
|
51
|
-
case operation
|
52
|
-
when :read
|
53
|
-
redis.get(i)
|
54
|
-
when :write
|
55
|
-
redis.incr(i)
|
56
|
-
else
|
57
|
-
raise "Unknown operation: #{operation}"
|
58
|
-
end
|
59
|
-
sleep sleep_duration
|
60
|
-
end
|
61
|
-
t2 = Time.now
|
62
|
-
|
63
|
-
requests_processed = end_index - start_index
|
64
|
-
time = t2 - t1
|
65
|
-
puts "#{t2.strftime("%H:%M")} [segment #{end_index + 1}] : Processed #{requests_processed} requests in #{time} seconds - #{(requests_processed/time).round} requests/sec"
|
66
|
-
end
|
67
|
-
|
68
|
-
else
|
69
|
-
raise "Unknown operation: #{operation}"
|
70
|
-
end
|
71
|
-
|