redis 3.3.1 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.travis/Gemfile +3 -1
  3. data/.travis.yml +36 -52
  4. data/CHANGELOG.md +32 -13
  5. data/Gemfile +0 -1
  6. data/README.md +31 -75
  7. data/benchmarking/logging.rb +1 -1
  8. data/bors.toml +14 -0
  9. data/lib/redis/client.rb +15 -11
  10. data/lib/redis/connection/command_helper.rb +2 -8
  11. data/lib/redis/connection/hiredis.rb +2 -2
  12. data/lib/redis/connection/ruby.rb +18 -20
  13. data/lib/redis/connection/synchrony.rb +12 -4
  14. data/lib/redis/connection.rb +2 -2
  15. data/lib/redis/distributed.rb +21 -8
  16. data/lib/redis/hash_ring.rb +20 -64
  17. data/lib/redis/pipeline.rb +0 -6
  18. data/lib/redis/version.rb +1 -1
  19. data/lib/redis.rb +102 -38
  20. data/makefile +42 -0
  21. data/redis.gemspec +7 -9
  22. data/test/bitpos_test.rb +13 -19
  23. data/test/blocking_commands_test.rb +3 -5
  24. data/test/client_test.rb +1 -1
  25. data/test/command_map_test.rb +3 -5
  26. data/test/commands_on_hashes_test.rb +2 -4
  27. data/test/commands_on_hyper_log_log_test.rb +3 -5
  28. data/test/commands_on_lists_test.rb +2 -4
  29. data/test/commands_on_sets_test.rb +2 -4
  30. data/test/commands_on_sorted_sets_test.rb +17 -4
  31. data/test/commands_on_strings_test.rb +3 -5
  32. data/test/commands_on_value_types_test.rb +44 -6
  33. data/test/connection_handling_test.rb +5 -7
  34. data/test/connection_test.rb +57 -0
  35. data/test/distributed_blocking_commands_test.rb +2 -4
  36. data/test/distributed_commands_on_hashes_test.rb +2 -4
  37. data/test/distributed_commands_on_hyper_log_log_test.rb +2 -4
  38. data/test/distributed_commands_on_lists_test.rb +2 -4
  39. data/test/distributed_commands_on_sets_test.rb +27 -4
  40. data/test/distributed_commands_on_sorted_sets_test.rb +2 -4
  41. data/test/distributed_commands_on_strings_test.rb +20 -10
  42. data/test/distributed_commands_on_value_types_test.rb +2 -4
  43. data/test/distributed_commands_requiring_clustering_test.rb +1 -3
  44. data/test/distributed_connection_handling_test.rb +1 -3
  45. data/test/distributed_internals_test.rb +8 -19
  46. data/test/distributed_key_tags_test.rb +4 -6
  47. data/test/distributed_persistence_control_commands_test.rb +1 -3
  48. data/test/distributed_publish_subscribe_test.rb +1 -3
  49. data/test/distributed_remote_server_control_commands_test.rb +1 -3
  50. data/test/distributed_scripting_test.rb +1 -3
  51. data/test/distributed_sorting_test.rb +1 -3
  52. data/test/distributed_test.rb +12 -14
  53. data/test/distributed_transactions_test.rb +1 -3
  54. data/test/encoding_test.rb +4 -8
  55. data/test/error_replies_test.rb +2 -4
  56. data/test/fork_safety_test.rb +1 -6
  57. data/test/helper.rb +10 -41
  58. data/test/helper_test.rb +1 -3
  59. data/test/internals_test.rb +27 -95
  60. data/test/lint/sets.rb +15 -0
  61. data/test/lint/strings.rb +6 -20
  62. data/test/lint/value_types.rb +8 -0
  63. data/test/persistence_control_commands_test.rb +1 -3
  64. data/test/pipelining_commands_test.rb +4 -8
  65. data/test/publish_subscribe_test.rb +1 -3
  66. data/test/remote_server_control_commands_test.rb +61 -4
  67. data/test/scanning_test.rb +1 -7
  68. data/test/scripting_test.rb +1 -3
  69. data/test/sentinel_command_test.rb +1 -3
  70. data/test/sentinel_test.rb +1 -3
  71. data/test/sorting_test.rb +1 -3
  72. data/test/ssl_test.rb +45 -42
  73. data/test/support/connection/hiredis.rb +1 -1
  74. data/test/support/connection/ruby.rb +1 -1
  75. data/test/support/connection/synchrony.rb +1 -1
  76. data/test/synchrony_driver.rb +6 -9
  77. data/test/thread_safety_test.rb +1 -3
  78. data/test/transactions_test.rb +1 -3
  79. data/test/unknown_commands_test.rb +1 -3
  80. data/test/url_param_test.rb +44 -46
  81. metadata +32 -16
  82. data/Rakefile +0 -87
data/test/ssl_test.rb CHANGED
@@ -1,66 +1,69 @@
1
- # encoding: UTF-8
1
+ require_relative "helper"
2
2
 
3
- if RUBY_VERSION >= "1.9.3"
4
- require File.expand_path("helper", File.dirname(__FILE__))
3
+ class SslTest < Test::Unit::TestCase
5
4
 
6
- class SslTest < Test::Unit::TestCase
5
+ include Helper::Client
7
6
 
8
- include Helper::Client
7
+ driver(:ruby) do
9
8
 
10
- driver(:ruby) do
9
+ def test_verified_ssl_connection
10
+ RedisMock.start({ :ping => proc { "+PONG" } }, ssl_server_opts("trusted")) do |port|
11
+ redis = Redis.new(:port => port, :ssl => true, :ssl_params => { :ca_file => ssl_ca_file })
12
+ assert_equal redis.ping, "PONG"
13
+ end
14
+ end
11
15
 
12
- def test_verified_ssl_connection
13
- RedisMock.start({ :ping => proc { "+PONG" } }, ssl_server_opts("trusted")) do |port|
16
+ def test_unverified_ssl_connection
17
+ assert_raise(OpenSSL::SSL::SSLError) do
18
+ RedisMock.start({ :ping => proc { "+PONG" } }, ssl_server_opts("untrusted")) do |port|
14
19
  redis = Redis.new(:port => port, :ssl => true, :ssl_params => { :ca_file => ssl_ca_file })
15
- assert_equal redis.ping, "PONG"
20
+ redis.ping
16
21
  end
17
22
  end
23
+ end
18
24
 
19
- def test_unverified_ssl_connection
20
- assert_raise(OpenSSL::SSL::SSLError) do
21
- RedisMock.start({ :ping => proc { "+PONG" } }, ssl_server_opts("untrusted")) do |port|
22
- redis = Redis.new(:port => port, :ssl => true, :ssl_params => { :ca_file => ssl_ca_file })
23
- redis.ping
24
- end
25
- end
25
+ def test_ssl_blocking
26
+ RedisMock.start({}, ssl_server_opts("trusted")) do |port|
27
+ redis = Redis.new(:port => port, :ssl => true, :ssl_params => { :ca_file => ssl_ca_file })
28
+ assert_equal redis.set("boom", "a" * 10_000_000), "OK"
26
29
  end
27
-
28
30
  end
29
31
 
30
- driver(:hiredis, :synchrony) do
32
+ end
33
+
34
+ driver(:hiredis, :synchrony) do
31
35
 
32
- def test_ssl_not_implemented_exception
33
- assert_raise(NotImplementedError) do
34
- RedisMock.start({ :ping => proc { "+PONG" } }, ssl_server_opts("trusted")) do |port|
35
- redis = Redis.new(:port => port, :ssl => true, :ssl_params => { :ca_file => ssl_ca_file })
36
- redis.ping
37
- end
36
+ def test_ssl_not_implemented_exception
37
+ assert_raise(NotImplementedError) do
38
+ RedisMock.start({ :ping => proc { "+PONG" } }, ssl_server_opts("trusted")) do |port|
39
+ redis = Redis.new(:port => port, :ssl => true, :ssl_params => { :ca_file => ssl_ca_file })
40
+ redis.ping
38
41
  end
39
42
  end
40
-
41
43
  end
42
44
 
43
- private
45
+ end
44
46
 
45
- def ssl_server_opts(prefix)
46
- ssl_cert = File.join(cert_path, "#{prefix}-cert.crt")
47
- ssl_key = File.join(cert_path, "#{prefix}-cert.key")
47
+ private
48
48
 
49
- {
50
- :ssl => true,
51
- :ssl_params => {
52
- :cert => OpenSSL::X509::Certificate.new(File.read(ssl_cert)),
53
- :key => OpenSSL::PKey::RSA.new(File.read(ssl_key))
54
- }
49
+ def ssl_server_opts(prefix)
50
+ ssl_cert = File.join(cert_path, "#{prefix}-cert.crt")
51
+ ssl_key = File.join(cert_path, "#{prefix}-cert.key")
52
+
53
+ {
54
+ :ssl => true,
55
+ :ssl_params => {
56
+ :cert => OpenSSL::X509::Certificate.new(File.read(ssl_cert)),
57
+ :key => OpenSSL::PKey::RSA.new(File.read(ssl_key))
55
58
  }
56
- end
59
+ }
60
+ end
57
61
 
58
- def ssl_ca_file
59
- File.join(cert_path, "trusted-ca.crt")
60
- end
62
+ def ssl_ca_file
63
+ File.join(cert_path, "trusted-ca.crt")
64
+ end
61
65
 
62
- def cert_path
63
- File.expand_path("../support/ssl/", __FILE__)
64
- end
66
+ def cert_path
67
+ File.expand_path("../support/ssl/", __FILE__)
65
68
  end
66
69
  end
@@ -1 +1 @@
1
- require "support/wire/thread"
1
+ require_relative "../wire/thread"
@@ -1 +1 @@
1
- require "support/wire/thread"
1
+ require_relative "../wire/thread"
@@ -1,4 +1,4 @@
1
- require "support/wire/synchrony"
1
+ require_relative "../wire/synchrony"
2
2
 
3
3
  module Helper
4
4
  def around
@@ -1,13 +1,10 @@
1
- # encoding: UTF-8
1
+ require "em-synchrony"
2
+ require "em-synchrony/connection_pool"
2
3
 
3
- require 'em-synchrony'
4
- require 'em-synchrony/connection_pool'
4
+ require_relative "../lib/redis"
5
+ require_relative "../lib/redis/connection/synchrony"
5
6
 
6
- require 'redis'
7
- require 'redis/connection/synchrony'
8
-
9
-
10
- require File.expand_path("./helper", File.dirname(__FILE__))
7
+ require_relative "helper"
11
8
 
12
9
  PORT = 6381
13
10
  OPTIONS = {:port => PORT, :db => 15}
@@ -55,7 +52,7 @@ EM.synchrony do
55
52
  assert_equal "s2", r.lpop("foo")
56
53
  assert_equal "s1", r.lpop("foo")
57
54
 
58
- assert_equal "OK", r.client.call(:quit)
55
+ assert_equal "OK", r._client.call(:quit)
59
56
  assert_equal "PONG", r.ping
60
57
 
61
58
 
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestThreadSafety < Test::Unit::TestCase
6
4
 
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestTransactions < Test::Unit::TestCase
6
4
 
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestUnknownCommands < Test::Unit::TestCase
6
4
 
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestUrlParam < Test::Unit::TestCase
6
4
 
@@ -9,104 +7,104 @@ class TestUrlParam < Test::Unit::TestCase
9
7
  def test_url_defaults_to_______________
10
8
  redis = Redis.new
11
9
 
12
- assert_equal "127.0.0.1", redis.client.host
13
- assert_equal 6379, redis.client.port
14
- assert_equal 0, redis.client.db
15
- assert_equal nil, redis.client.password
10
+ assert_equal "127.0.0.1", redis._client.host
11
+ assert_equal 6379, redis._client.port
12
+ assert_equal 0, redis._client.db
13
+ assert_equal nil, redis._client.password
16
14
  end
17
15
 
18
16
  def test_allows_to_pass_in_a_url
19
17
  redis = Redis.new :url => "redis://:secr3t@foo.com:999/2"
20
18
 
21
- assert_equal "foo.com", redis.client.host
22
- assert_equal 999, redis.client.port
23
- assert_equal 2, redis.client.db
24
- assert_equal "secr3t", redis.client.password
19
+ assert_equal "foo.com", redis._client.host
20
+ assert_equal 999, redis._client.port
21
+ assert_equal 2, redis._client.db
22
+ assert_equal "secr3t", redis._client.password
25
23
  end
26
24
 
27
25
  def test_allows_to_pass_in_a_url_with_string_key
28
26
  redis = Redis.new "url" => "redis://:secr3t@foo.com:999/2"
29
27
 
30
- assert_equal "foo.com", redis.client.host
31
- assert_equal 999, redis.client.port
32
- assert_equal 2, redis.client.db
33
- assert_equal "secr3t", redis.client.password
28
+ assert_equal "foo.com", redis._client.host
29
+ assert_equal 999, redis._client.port
30
+ assert_equal 2, redis._client.db
31
+ assert_equal "secr3t", redis._client.password
34
32
  end
35
33
 
36
34
  def test_unescape_password_from_url
37
35
  redis = Redis.new :url => "redis://:secr3t%3A@foo.com:999/2"
38
36
 
39
- assert_equal "secr3t:", redis.client.password
37
+ assert_equal "secr3t:", redis._client.password
40
38
  end
41
39
 
42
40
  def test_unescape_password_from_url_with_string_key
43
41
  redis = Redis.new "url" => "redis://:secr3t%3A@foo.com:999/2"
44
42
 
45
- assert_equal "secr3t:", redis.client.password
43
+ assert_equal "secr3t:", redis._client.password
46
44
  end
47
45
 
48
46
  def test_does_not_unescape_password_when_explicitly_passed
49
47
  redis = Redis.new :url => "redis://:secr3t%3A@foo.com:999/2", :password => "secr3t%3A"
50
48
 
51
- assert_equal "secr3t%3A", redis.client.password
49
+ assert_equal "secr3t%3A", redis._client.password
52
50
  end
53
51
 
54
52
  def test_does_not_unescape_password_when_explicitly_passed_with_string_key
55
53
  redis = Redis.new :url => "redis://:secr3t%3A@foo.com:999/2", "password" => "secr3t%3A"
56
54
 
57
- assert_equal "secr3t%3A", redis.client.password
55
+ assert_equal "secr3t%3A", redis._client.password
58
56
  end
59
57
 
60
58
  def test_override_url_if_path_option_is_passed
61
59
  redis = Redis.new :url => "redis://:secr3t@foo.com/foo:999/2", :path => "/tmp/redis.sock"
62
60
 
63
- assert_equal "/tmp/redis.sock", redis.client.path
64
- assert_equal nil, redis.client.host
65
- assert_equal nil, redis.client.port
61
+ assert_equal "/tmp/redis.sock", redis._client.path
62
+ assert_equal nil, redis._client.host
63
+ assert_equal nil, redis._client.port
66
64
  end
67
65
 
68
66
  def test_override_url_if_path_option_is_passed_with_string_key
69
67
  redis = Redis.new :url => "redis://:secr3t@foo.com/foo:999/2", "path" => "/tmp/redis.sock"
70
68
 
71
- assert_equal "/tmp/redis.sock", redis.client.path
72
- assert_equal nil, redis.client.host
73
- assert_equal nil, redis.client.port
69
+ assert_equal "/tmp/redis.sock", redis._client.path
70
+ assert_equal nil, redis._client.host
71
+ assert_equal nil, redis._client.port
74
72
  end
75
73
 
76
74
  def test_overrides_url_if_another_connection_option_is_passed
77
75
  redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", :port => 1000
78
76
 
79
- assert_equal "foo.com", redis.client.host
80
- assert_equal 1000, redis.client.port
81
- assert_equal 2, redis.client.db
82
- assert_equal "secr3t", redis.client.password
77
+ assert_equal "foo.com", redis._client.host
78
+ assert_equal 1000, redis._client.port
79
+ assert_equal 2, redis._client.db
80
+ assert_equal "secr3t", redis._client.password
83
81
  end
84
82
 
85
83
  def test_overrides_url_if_another_connection_option_is_passed_with_string_key
86
84
  redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", "port" => 1000
87
85
 
88
- assert_equal "foo.com", redis.client.host
89
- assert_equal 1000, redis.client.port
90
- assert_equal 2, redis.client.db
91
- assert_equal "secr3t", redis.client.password
86
+ assert_equal "foo.com", redis._client.host
87
+ assert_equal 1000, redis._client.port
88
+ assert_equal 2, redis._client.db
89
+ assert_equal "secr3t", redis._client.password
92
90
  end
93
91
 
94
92
  def test_does_not_overrides_url_if_a_nil_option_is_passed
95
93
  redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", :port => nil
96
94
 
97
- assert_equal "foo.com", redis.client.host
98
- assert_equal 999, redis.client.port
99
- assert_equal 2, redis.client.db
100
- assert_equal "secr3t", redis.client.password
95
+ assert_equal "foo.com", redis._client.host
96
+ assert_equal 999, redis._client.port
97
+ assert_equal 2, redis._client.db
98
+ assert_equal "secr3t", redis._client.password
101
99
  end
102
100
 
103
101
  def test_does_not_overrides_url_if_a_nil_option_is_passed_with_string_key
104
102
  redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", "port" => nil
105
103
 
106
- assert_equal "foo.com", redis.client.host
107
- assert_equal 999, redis.client.port
108
- assert_equal 2, redis.client.db
109
- assert_equal "secr3t", redis.client.password
104
+ assert_equal "foo.com", redis._client.host
105
+ assert_equal 999, redis._client.port
106
+ assert_equal 2, redis._client.db
107
+ assert_equal "secr3t", redis._client.password
110
108
  end
111
109
 
112
110
  def test_does_not_modify_the_passed_options
@@ -122,10 +120,10 @@ class TestUrlParam < Test::Unit::TestCase
122
120
 
123
121
  redis = Redis.new
124
122
 
125
- assert_equal "foo.com", redis.client.host
126
- assert_equal 999, redis.client.port
127
- assert_equal 2, redis.client.db
128
- assert_equal "secr3t", redis.client.password
123
+ assert_equal "foo.com", redis._client.host
124
+ assert_equal 999, redis._client.port
125
+ assert_equal 2, redis._client.db
126
+ assert_equal "secr3t", redis._client.password
129
127
 
130
128
  ENV.delete("REDIS_URL")
131
129
  end
@@ -133,6 +131,6 @@ class TestUrlParam < Test::Unit::TestCase
133
131
  def test_defaults_to_localhost
134
132
  redis = Redis.new(:url => "redis:///")
135
133
 
136
- assert_equal "127.0.0.1", redis.client.host
134
+ assert_equal "127.0.0.1", redis._client.host
137
135
  end
138
136
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -16,40 +16,53 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2016-07-18 00:00:00.000000000 Z
19
+ date: 2017-09-28 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rake
22
+ name: test-unit
23
23
  requirement: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "<"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 11.0.0
27
+ version: 3.1.5
28
28
  type: :development
29
29
  prerelease: false
30
30
  version_requirements: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "<"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 11.0.0
34
+ version: 3.1.5
35
35
  - !ruby/object:Gem::Dependency
36
- name: test-unit
36
+ name: hiredis
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 3.1.5
41
+ version: '0'
42
42
  type: :development
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 3.1.5
48
+ version: '0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: em-synchrony
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
49
63
  description: |2
50
64
  A Ruby client that tries to match Redis' API one-to-one, while still
51
- providing an idiomatic interface. It features thread-safety,
52
- client-side sharding, pipelining, and an obsession for performance.
65
+ providing an idiomatic interface.
53
66
  email:
54
67
  - redis-db@googlegroups.com
55
68
  executables: []
@@ -64,12 +77,12 @@ files:
64
77
  - Gemfile
65
78
  - LICENSE
66
79
  - README.md
67
- - Rakefile
68
80
  - benchmarking/logging.rb
69
81
  - benchmarking/pipeline.rb
70
82
  - benchmarking/speed.rb
71
83
  - benchmarking/suite.rb
72
84
  - benchmarking/worker.rb
85
+ - bors.toml
73
86
  - examples/basic.rb
74
87
  - examples/consistency.rb
75
88
  - examples/dist_redis.rb
@@ -96,6 +109,7 @@ files:
96
109
  - lib/redis/pipeline.rb
97
110
  - lib/redis/subscribe.rb
98
111
  - lib/redis/version.rb
112
+ - makefile
99
113
  - redis.gemspec
100
114
  - test/bitpos_test.rb
101
115
  - test/blocking_commands_test.rb
@@ -109,6 +123,7 @@ files:
109
123
  - test/commands_on_strings_test.rb
110
124
  - test/commands_on_value_types_test.rb
111
125
  - test/connection_handling_test.rb
126
+ - test/connection_test.rb
112
127
  - test/db/.gitkeep
113
128
  - test/distributed_blocking_commands_test.rb
114
129
  - test/distributed_commands_on_hashes_test.rb
@@ -186,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
201
  requirements:
187
202
  - - ">="
188
203
  - !ruby/object:Gem::Version
189
- version: '0'
204
+ version: 2.2.2
190
205
  required_rubygems_version: !ruby/object:Gem::Requirement
191
206
  requirements:
192
207
  - - ">="
@@ -211,6 +226,7 @@ test_files:
211
226
  - test/commands_on_strings_test.rb
212
227
  - test/commands_on_value_types_test.rb
213
228
  - test/connection_handling_test.rb
229
+ - test/connection_test.rb
214
230
  - test/db/.gitkeep
215
231
  - test/distributed_blocking_commands_test.rb
216
232
  - test/distributed_commands_on_hashes_test.rb
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