redis 4.0.3 → 4.5.0

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 (157) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +110 -0
  3. data/README.md +126 -17
  4. data/lib/redis/client.rb +130 -82
  5. data/lib/redis/cluster/command_loader.rb +8 -7
  6. data/lib/redis/cluster/node.rb +5 -1
  7. data/lib/redis/cluster/node_key.rb +3 -7
  8. data/lib/redis/cluster/node_loader.rb +2 -0
  9. data/lib/redis/cluster/option.rb +31 -14
  10. data/lib/redis/cluster/slot.rb +30 -13
  11. data/lib/redis/cluster/slot_loader.rb +6 -4
  12. data/lib/redis/cluster.rb +23 -17
  13. data/lib/redis/connection/command_helper.rb +5 -2
  14. data/lib/redis/connection/hiredis.rb +4 -3
  15. data/lib/redis/connection/registry.rb +2 -1
  16. data/lib/redis/connection/ruby.rb +139 -106
  17. data/lib/redis/connection/synchrony.rb +9 -4
  18. data/lib/redis/connection.rb +2 -0
  19. data/lib/redis/distributed.rb +171 -70
  20. data/lib/redis/errors.rb +2 -0
  21. data/lib/redis/hash_ring.rb +15 -14
  22. data/lib/redis/pipeline.rb +46 -8
  23. data/lib/redis/subscribe.rb +11 -12
  24. data/lib/redis/version.rb +3 -1
  25. data/lib/redis.rb +1239 -426
  26. metadata +16 -262
  27. data/.gitignore +0 -19
  28. data/.travis/Gemfile +0 -18
  29. data/.travis.yml +0 -61
  30. data/.yardopts +0 -3
  31. data/Gemfile +0 -8
  32. data/benchmarking/logging.rb +0 -71
  33. data/benchmarking/pipeline.rb +0 -51
  34. data/benchmarking/speed.rb +0 -21
  35. data/benchmarking/suite.rb +0 -24
  36. data/benchmarking/worker.rb +0 -71
  37. data/bin/build +0 -71
  38. data/bors.toml +0 -14
  39. data/examples/basic.rb +0 -15
  40. data/examples/consistency.rb +0 -114
  41. data/examples/dist_redis.rb +0 -43
  42. data/examples/incr-decr.rb +0 -17
  43. data/examples/list.rb +0 -26
  44. data/examples/pubsub.rb +0 -37
  45. data/examples/sentinel/sentinel.conf +0 -9
  46. data/examples/sentinel/start +0 -49
  47. data/examples/sentinel.rb +0 -41
  48. data/examples/sets.rb +0 -36
  49. data/examples/unicorn/config.ru +0 -3
  50. data/examples/unicorn/unicorn.rb +0 -20
  51. data/makefile +0 -74
  52. data/redis.gemspec +0 -43
  53. data/test/bitpos_test.rb +0 -63
  54. data/test/blocking_commands_test.rb +0 -40
  55. data/test/client_test.rb +0 -76
  56. data/test/cluster_abnormal_state_test.rb +0 -38
  57. data/test/cluster_blocking_commands_test.rb +0 -15
  58. data/test/cluster_client_internals_test.rb +0 -77
  59. data/test/cluster_client_key_hash_tags_test.rb +0 -88
  60. data/test/cluster_client_options_test.rb +0 -147
  61. data/test/cluster_client_pipelining_test.rb +0 -59
  62. data/test/cluster_client_replicas_test.rb +0 -36
  63. data/test/cluster_client_slots_test.rb +0 -94
  64. data/test/cluster_client_transactions_test.rb +0 -71
  65. data/test/cluster_commands_on_cluster_test.rb +0 -165
  66. data/test/cluster_commands_on_connection_test.rb +0 -40
  67. data/test/cluster_commands_on_geo_test.rb +0 -74
  68. data/test/cluster_commands_on_hashes_test.rb +0 -11
  69. data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
  70. data/test/cluster_commands_on_keys_test.rb +0 -134
  71. data/test/cluster_commands_on_lists_test.rb +0 -15
  72. data/test/cluster_commands_on_pub_sub_test.rb +0 -101
  73. data/test/cluster_commands_on_scripting_test.rb +0 -56
  74. data/test/cluster_commands_on_server_test.rb +0 -221
  75. data/test/cluster_commands_on_sets_test.rb +0 -39
  76. data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
  77. data/test/cluster_commands_on_streams_test.rb +0 -196
  78. data/test/cluster_commands_on_strings_test.rb +0 -15
  79. data/test/cluster_commands_on_transactions_test.rb +0 -41
  80. data/test/cluster_commands_on_value_types_test.rb +0 -14
  81. data/test/command_map_test.rb +0 -28
  82. data/test/commands_on_geo_test.rb +0 -116
  83. data/test/commands_on_hashes_test.rb +0 -7
  84. data/test/commands_on_hyper_log_log_test.rb +0 -7
  85. data/test/commands_on_lists_test.rb +0 -7
  86. data/test/commands_on_sets_test.rb +0 -7
  87. data/test/commands_on_sorted_sets_test.rb +0 -7
  88. data/test/commands_on_strings_test.rb +0 -7
  89. data/test/commands_on_value_types_test.rb +0 -207
  90. data/test/connection_handling_test.rb +0 -275
  91. data/test/connection_test.rb +0 -57
  92. data/test/db/.gitkeep +0 -0
  93. data/test/distributed_blocking_commands_test.rb +0 -52
  94. data/test/distributed_commands_on_hashes_test.rb +0 -21
  95. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
  96. data/test/distributed_commands_on_lists_test.rb +0 -19
  97. data/test/distributed_commands_on_sets_test.rb +0 -105
  98. data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
  99. data/test/distributed_commands_on_strings_test.rb +0 -79
  100. data/test/distributed_commands_on_value_types_test.rb +0 -129
  101. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  102. data/test/distributed_connection_handling_test.rb +0 -21
  103. data/test/distributed_internals_test.rb +0 -68
  104. data/test/distributed_key_tags_test.rb +0 -50
  105. data/test/distributed_persistence_control_commands_test.rb +0 -24
  106. data/test/distributed_publish_subscribe_test.rb +0 -90
  107. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  108. data/test/distributed_scripting_test.rb +0 -100
  109. data/test/distributed_sorting_test.rb +0 -18
  110. data/test/distributed_test.rb +0 -56
  111. data/test/distributed_transactions_test.rb +0 -30
  112. data/test/encoding_test.rb +0 -14
  113. data/test/error_replies_test.rb +0 -57
  114. data/test/fork_safety_test.rb +0 -60
  115. data/test/helper.rb +0 -345
  116. data/test/helper_test.rb +0 -22
  117. data/test/internals_test.rb +0 -408
  118. data/test/lint/blocking_commands.rb +0 -174
  119. data/test/lint/hashes.rb +0 -203
  120. data/test/lint/hyper_log_log.rb +0 -74
  121. data/test/lint/lists.rb +0 -159
  122. data/test/lint/sets.rb +0 -282
  123. data/test/lint/sorted_sets.rb +0 -497
  124. data/test/lint/strings.rb +0 -348
  125. data/test/lint/value_types.rb +0 -130
  126. data/test/persistence_control_commands_test.rb +0 -24
  127. data/test/pipelining_commands_test.rb +0 -246
  128. data/test/publish_subscribe_test.rb +0 -280
  129. data/test/remote_server_control_commands_test.rb +0 -175
  130. data/test/scanning_test.rb +0 -407
  131. data/test/scripting_test.rb +0 -76
  132. data/test/sentinel_command_test.rb +0 -78
  133. data/test/sentinel_test.rb +0 -253
  134. data/test/sorting_test.rb +0 -57
  135. data/test/ssl_test.rb +0 -69
  136. data/test/support/cluster/orchestrator.rb +0 -199
  137. data/test/support/connection/hiredis.rb +0 -1
  138. data/test/support/connection/ruby.rb +0 -1
  139. data/test/support/connection/synchrony.rb +0 -17
  140. data/test/support/redis_mock.rb +0 -130
  141. data/test/support/ssl/gen_certs.sh +0 -31
  142. data/test/support/ssl/trusted-ca.crt +0 -25
  143. data/test/support/ssl/trusted-ca.key +0 -27
  144. data/test/support/ssl/trusted-cert.crt +0 -81
  145. data/test/support/ssl/trusted-cert.key +0 -28
  146. data/test/support/ssl/untrusted-ca.crt +0 -26
  147. data/test/support/ssl/untrusted-ca.key +0 -27
  148. data/test/support/ssl/untrusted-cert.crt +0 -82
  149. data/test/support/ssl/untrusted-cert.key +0 -28
  150. data/test/support/wire/synchrony.rb +0 -24
  151. data/test/support/wire/thread.rb +0 -5
  152. data/test/synchrony_driver.rb +0 -85
  153. data/test/test.conf.erb +0 -9
  154. data/test/thread_safety_test.rb +0 -60
  155. data/test/transactions_test.rb +0 -272
  156. data/test/unknown_commands_test.rb +0 -12
  157. data/test/url_param_test.rb +0 -136
@@ -1,116 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestCommandsGeo < Test::Unit::TestCase
4
- include Helper::Client
5
-
6
- def setup
7
- super
8
-
9
- target_version "3.2.0" do
10
- added_items_count = r.geoadd("Sicily", 13.361389, 38.115556, "Palermo", 15.087269, 37.502669, "Catania")
11
- assert_equal 2, added_items_count
12
- end
13
- end
14
-
15
- def test_georadius_with_sort
16
- target_version "3.2.0" do
17
- nearest_cities = r.georadius("Sicily", 15, 37, 200, 'km', sort: 'asc')
18
- assert_equal %w(Catania Palermo), nearest_cities
19
-
20
- farthest_cities = r.georadius("Sicily", 15, 37, 200, 'km', sort: 'desc')
21
- assert_equal %w(Palermo Catania), farthest_cities
22
- end
23
- end
24
-
25
- def test_georadius_with_count
26
- target_version "3.2.0" do
27
- city = r.georadius("Sicily", 15, 37, 200, 'km', count: 1)
28
- assert_equal %w(Catania), city
29
- end
30
- end
31
-
32
- def test_georadius_with_options_count_sort
33
- target_version "3.2.0" do
34
- city = r.georadius("Sicily", 15, 37, 200, 'km', sort: :desc, options: :WITHDIST, count: 1)
35
- assert_equal [["Palermo", "190.4424"]], city
36
- end
37
- end
38
-
39
- def test_georadiusbymember_with_sort
40
- target_version "3.2.0" do
41
- nearest_cities = r.georadiusbymember("Sicily", "Catania", 200, 'km', sort: 'asc')
42
- assert_equal %w(Catania Palermo), nearest_cities
43
-
44
- farthest_cities = r.georadiusbymember("Sicily", "Catania", 200, 'km', sort: 'desc')
45
- assert_equal %w(Palermo Catania), farthest_cities
46
- end
47
- end
48
-
49
- def test_georadiusbymember_with_count
50
- target_version "3.2.0" do
51
- city = r.georadiusbymember("Sicily", "Catania", 200, 'km', count: 1)
52
- assert_equal %w(Catania), city
53
- end
54
- end
55
-
56
- def test_georadiusbymember_with_options_count_sort
57
- target_version "3.2.0" do
58
- city = r.georadiusbymember("Sicily", "Catania", 200, 'km', sort: :desc, options: :WITHDIST, count: 1)
59
- assert_equal [["Palermo", "166.2742"]], city
60
- end
61
- end
62
-
63
- def test_geopos
64
- target_version "3.2.0" do
65
- location = r.geopos("Sicily", "Catania")
66
- assert_equal [["15.08726745843887329", "37.50266842333162032"]], location
67
-
68
- locations = r.geopos("Sicily", ["Palermo", "Catania"])
69
- assert_equal [["13.36138933897018433", "38.11555639549629859"], ["15.08726745843887329", "37.50266842333162032"]], locations
70
- end
71
- end
72
-
73
- def test_geopos_nonexistant_location
74
- target_version "3.2.0" do
75
- location = r.geopos("Sicily", "Rome")
76
- assert_equal [nil], location
77
-
78
- locations = r.geopos("Sicily", ["Rome", "Catania"])
79
- assert_equal [nil, ["15.08726745843887329", "37.50266842333162032"]], locations
80
- end
81
- end
82
-
83
- def test_geodist
84
- target_version "3.2.0" do
85
- distination_in_meters = r.geodist("Sicily", "Palermo", "Catania")
86
- assert_equal "166274.1516", distination_in_meters
87
-
88
- distination_in_feet = r.geodist("Sicily", "Palermo", "Catania", 'ft')
89
- assert_equal "545518.8700", distination_in_feet
90
- end
91
- end
92
-
93
- def test_geodist_with_nonexistant_location
94
- target_version "3.2.0" do
95
- distination = r.geodist("Sicily", "Palermo", "Rome")
96
- assert_equal nil, distination
97
- end
98
- end
99
-
100
- def test_geohash
101
- target_version "3.2.0" do
102
- geohash = r.geohash("Sicily", "Palermo")
103
- assert_equal ["sqc8b49rny0"], geohash
104
-
105
- geohashes = r.geohash("Sicily", ["Palermo", "Catania"])
106
- assert_equal %w(sqc8b49rny0 sqdtr74hyu0), geohashes
107
- end
108
- end
109
-
110
- def test_geohash_with_nonexistant_location
111
- target_version "3.2.0" do
112
- geohashes = r.geohash("Sicily", ["Palermo", "Rome"])
113
- assert_equal ["sqc8b49rny0", nil], geohashes
114
- end
115
- end
116
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/hashes'
3
-
4
- class TestCommandsOnHashes < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::Hashes
7
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/hyper_log_log'
3
-
4
- class TestCommandsOnHyperLogLog < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::HyperLogLog
7
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/lists'
3
-
4
- class TestCommandsOnLists < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::Lists
7
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/sets'
3
-
4
- class TestCommandsOnSets < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::Sets
7
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/sorted_sets'
3
-
4
- class TestCommandsOnSortedSets < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::SortedSets
7
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/strings'
3
-
4
- class TestCommandsOnStrings < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::Strings
7
- end
@@ -1,207 +0,0 @@
1
- require_relative "helper"
2
- require_relative "lint/value_types"
3
-
4
- class TestCommandsOnValueTypes < Test::Unit::TestCase
5
-
6
- include Helper::Client
7
- include Lint::ValueTypes
8
-
9
- def test_del
10
- r.set "foo", "s1"
11
- r.set "bar", "s2"
12
- r.set "baz", "s3"
13
-
14
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
15
-
16
- assert_equal 1, r.del("foo")
17
-
18
- assert_equal ["bar", "baz"], r.keys("*").sort
19
-
20
- assert_equal 2, r.del("bar", "baz")
21
-
22
- assert_equal [], r.keys("*").sort
23
- end
24
-
25
- def test_del_with_array_argument
26
- r.set "foo", "s1"
27
- r.set "bar", "s2"
28
- r.set "baz", "s3"
29
-
30
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
31
-
32
- assert_equal 1, r.del(["foo"])
33
-
34
- assert_equal ["bar", "baz"], r.keys("*").sort
35
-
36
- assert_equal 2, r.del(["bar", "baz"])
37
-
38
- assert_equal [], r.keys("*").sort
39
- end
40
-
41
- def test_unlink
42
- target_version "4.0.0" do
43
- r.set "foo", "s1"
44
- r.set "bar", "s2"
45
- r.set "baz", "s3"
46
-
47
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
48
-
49
- assert_equal 1, r.unlink("foo")
50
-
51
- assert_equal ["bar", "baz"], r.keys("*").sort
52
-
53
- assert_equal 2, r.unlink("bar", "baz")
54
-
55
- assert_equal [], r.keys("*").sort
56
- end
57
- end
58
-
59
- def test_unlink_with_array_argument
60
- target_version "4.0.0" do
61
- r.set "foo", "s1"
62
- r.set "bar", "s2"
63
- r.set "baz", "s3"
64
-
65
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
66
-
67
- assert_equal 1, r.unlink(["foo"])
68
-
69
- assert_equal ["bar", "baz"], r.keys("*").sort
70
-
71
- assert_equal 2, r.unlink(["bar", "baz"])
72
-
73
- assert_equal [], r.keys("*").sort
74
- end
75
- end
76
-
77
- def test_randomkey
78
- assert r.randomkey.to_s.empty?
79
-
80
- r.set("foo", "s1")
81
-
82
- assert_equal "foo", r.randomkey
83
-
84
- r.set("bar", "s2")
85
-
86
- 4.times do
87
- assert ["foo", "bar"].include?(r.randomkey)
88
- end
89
- end
90
-
91
- def test_rename
92
- r.set("foo", "s1")
93
- r.rename "foo", "bar"
94
-
95
- assert_equal "s1", r.get("bar")
96
- assert_equal nil, r.get("foo")
97
- end
98
-
99
- def test_renamenx
100
- r.set("foo", "s1")
101
- r.set("bar", "s2")
102
-
103
- assert_equal false, r.renamenx("foo", "bar")
104
-
105
- assert_equal "s1", r.get("foo")
106
- assert_equal "s2", r.get("bar")
107
- end
108
-
109
- def test_dbsize
110
- assert_equal 0, r.dbsize
111
-
112
- r.set("foo", "s1")
113
-
114
- assert_equal 1, r.dbsize
115
- end
116
-
117
- def test_flushdb
118
- # Test defaults
119
- r.set("foo", "s1")
120
- r.set("bar", "s2")
121
-
122
- assert_equal 2, r.dbsize
123
-
124
- r.flushdb
125
-
126
- assert_equal 0, r.dbsize
127
-
128
- # Test sync
129
- r.set("foo", "s1")
130
- r.set("bar", "s2")
131
-
132
- assert_equal 2, r.dbsize
133
-
134
- r.flushdb(:async => false)
135
-
136
- assert_equal 0, r.dbsize
137
-
138
- # Test async
139
- target_version "3.9.101" do
140
- r.set("foo", "s1")
141
- r.set("bar", "s2")
142
-
143
- assert_equal 2, r.dbsize
144
-
145
- r.flushdb(:async => true)
146
-
147
- assert_equal 0, r.dbsize
148
-
149
- redis_mock(:flushdb => lambda { |args| "+FLUSHDB #{args.upcase}" }) do |redis|
150
- assert_equal "FLUSHDB ASYNC", redis.flushdb(:async => true)
151
- end
152
- end
153
- end
154
-
155
- def test_flushall
156
- # Test defaults
157
- redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
158
- assert_equal "FLUSHALL", redis.flushall
159
- end
160
-
161
- # Test sync
162
- redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
163
- assert_equal "FLUSHALL", redis.flushall(:async => false)
164
- end
165
-
166
- # Test async
167
- target_version "3.9.101" do
168
- redis_mock(:flushall => lambda { |args| "+FLUSHALL #{args.upcase}" }) do |redis|
169
- assert_equal "FLUSHALL ASYNC", redis.flushall(:async => true)
170
- end
171
- end
172
- end
173
-
174
- def test_migrate
175
- redis_mock(:migrate => lambda { |*args| args }) do |redis|
176
- options = { :host => "127.0.0.1", :port => 1234 }
177
-
178
- ex = assert_raise(RuntimeError) do
179
- redis.migrate("foo", options.reject { |key, _| key == :host })
180
- end
181
- assert ex.message =~ /host not specified/
182
-
183
- ex = assert_raise(RuntimeError) do
184
- redis.migrate("foo", options.reject { |key, _| key == :port })
185
- end
186
- assert ex.message =~ /port not specified/
187
-
188
- default_db = redis._client.db.to_i
189
- default_timeout = redis._client.timeout.to_i
190
-
191
- # Test defaults
192
- actual = redis.migrate("foo", options)
193
- expected = ["127.0.0.1", "1234", "foo", default_db.to_s, default_timeout.to_s]
194
- assert_equal expected, actual
195
-
196
- # Test db override
197
- actual = redis.migrate("foo", options.merge(:db => default_db + 1))
198
- expected = ["127.0.0.1", "1234", "foo", (default_db + 1).to_s, default_timeout.to_s]
199
- assert_equal expected, actual
200
-
201
- # Test timeout override
202
- actual = redis.migrate("foo", options.merge(:timeout => default_timeout + 1))
203
- expected = ["127.0.0.1", "1234", "foo", default_db.to_s, (default_timeout + 1).to_s]
204
- assert_equal expected, actual
205
- end
206
- end
207
- end
@@ -1,275 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestConnectionHandling < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_auth
8
- commands = {
9
- :auth => lambda { |password| $auth = password; "+OK" },
10
- :get => lambda { |key| $auth == "secret" ? "$3\r\nbar" : "$-1" },
11
- }
12
-
13
- redis_mock(commands, :password => "secret") do |redis|
14
- assert_equal "bar", redis.get("foo")
15
- end
16
- end
17
-
18
- def test_id
19
- commands = {
20
- :client => lambda { |cmd, name| $name = [cmd, name]; "+OK" },
21
- :ping => lambda { "+PONG" },
22
- }
23
-
24
- redis_mock(commands, :id => "client-name") do |redis|
25
- assert_equal "PONG", redis.ping
26
- end
27
-
28
- assert_equal ["setname","client-name"], $name
29
- end
30
-
31
- def test_ping
32
- assert_equal "PONG", r.ping
33
- end
34
-
35
- def test_select
36
- r.set "foo", "bar"
37
-
38
- r.select 14
39
- assert_equal nil, r.get("foo")
40
-
41
- r._client.disconnect
42
-
43
- assert_equal nil, r.get("foo")
44
- end
45
-
46
- def test_quit
47
- r.quit
48
-
49
- assert !r._client.connected?
50
- end
51
-
52
- def test_close
53
- quit = 0
54
-
55
- commands = {
56
- :quit => lambda do
57
- quit += 1
58
- "+OK"
59
- end
60
- }
61
-
62
- redis_mock(commands) do |redis|
63
- assert_equal 0, quit
64
-
65
- redis.quit
66
-
67
- assert_equal 1, quit
68
-
69
- redis.ping
70
-
71
- redis.close
72
-
73
- assert_equal 1, quit
74
-
75
- assert !redis.connected?
76
- end
77
- end
78
-
79
- def test_disconnect
80
- quit = 0
81
-
82
- commands = {
83
- :quit => lambda do
84
- quit += 1
85
- "+OK"
86
- end
87
- }
88
-
89
- redis_mock(commands) do |redis|
90
- assert_equal 0, quit
91
-
92
- redis.quit
93
-
94
- assert_equal 1, quit
95
-
96
- redis.ping
97
-
98
- redis.disconnect!
99
-
100
- assert_equal 1, quit
101
-
102
- assert !redis.connected?
103
- end
104
- end
105
-
106
- def test_shutdown
107
- commands = {
108
- :shutdown => lambda { :exit }
109
- }
110
-
111
- redis_mock(commands) do |redis|
112
- # SHUTDOWN does not reply: test that it does not raise here.
113
- assert_equal nil, redis.shutdown
114
- end
115
- end
116
-
117
- def test_shutdown_with_error
118
- connections = 0
119
- commands = {
120
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
121
- :connections => lambda { ":#{connections}\r\n" },
122
- :shutdown => lambda { "-ERR could not shutdown\r\n" }
123
- }
124
-
125
- redis_mock(commands) do |redis|
126
- connections = redis.connections
127
-
128
- # SHUTDOWN replies with an error: test that it gets raised
129
- assert_raise Redis::CommandError do
130
- redis.shutdown
131
- end
132
-
133
- # The connection should remain in tact
134
- assert_equal connections, redis.connections
135
- end
136
- end
137
-
138
- def test_shutdown_from_pipeline
139
- commands = {
140
- :shutdown => lambda { :exit }
141
- }
142
-
143
- redis_mock(commands) do |redis|
144
- result = redis.pipelined do
145
- redis.shutdown
146
- end
147
-
148
- assert_equal nil, result
149
- assert !redis._client.connected?
150
- end
151
- end
152
-
153
- def test_shutdown_with_error_from_pipeline
154
- connections = 0
155
- commands = {
156
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
157
- :connections => lambda { ":#{connections}\r\n" },
158
- :shutdown => lambda { "-ERR could not shutdown\r\n" }
159
- }
160
-
161
- redis_mock(commands) do |redis|
162
- connections = redis.connections
163
-
164
- # SHUTDOWN replies with an error: test that it gets raised
165
- assert_raise Redis::CommandError do
166
- redis.pipelined do
167
- redis.shutdown
168
- end
169
- end
170
-
171
- # The connection should remain in tact
172
- assert_equal connections, redis.connections
173
- end
174
- end
175
-
176
- def test_shutdown_from_multi_exec
177
- commands = {
178
- :multi => lambda { "+OK\r\n" },
179
- :shutdown => lambda { "+QUEUED\r\n" },
180
- :exec => lambda { :exit }
181
- }
182
-
183
- redis_mock(commands) do |redis|
184
- result = redis.multi do
185
- redis.shutdown
186
- end
187
-
188
- assert_equal nil, result
189
- assert !redis._client.connected?
190
- end
191
- end
192
-
193
- def test_shutdown_with_error_from_multi_exec
194
- connections = 0
195
- commands = {
196
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
197
- :connections => lambda { ":#{connections}\r\n" },
198
- :multi => lambda { "+OK\r\n" },
199
- :shutdown => lambda { "+QUEUED\r\n" },
200
- :exec => lambda { "*1\r\n-ERR could not shutdown\r\n" }
201
- }
202
-
203
- redis_mock(commands) do |redis|
204
- connections = redis.connections
205
-
206
- # SHUTDOWN replies with an error: test that it gets returned
207
- # We should test for Redis::CommandError here, but hiredis doesn't yet do
208
- # custom error classes.
209
- err = nil
210
-
211
- begin
212
- redis.multi { redis.shutdown }
213
- rescue => err
214
- end
215
-
216
- assert err.kind_of?(StandardError)
217
-
218
- # The connection should remain intact
219
- assert_equal connections, redis.connections
220
- end
221
- end
222
-
223
- def test_slaveof
224
- redis_mock(:slaveof => lambda { |host, port| "+SLAVEOF #{host} #{port}" }) do |redis|
225
- assert_equal "SLAVEOF somehost 6381", redis.slaveof("somehost", 6381)
226
- end
227
- end
228
-
229
- def test_bgrewriteaof
230
- redis_mock(:bgrewriteaof => lambda { "+BGREWRITEAOF" }) do |redis|
231
- assert_equal "BGREWRITEAOF", redis.bgrewriteaof
232
- end
233
- end
234
-
235
- def test_config_get
236
- assert r.config(:get, "*")["timeout"] != nil
237
-
238
- config = r.config(:get, "timeout")
239
- assert_equal ["timeout"], config.keys
240
- assert config.values.compact.size > 0
241
- end
242
-
243
- def test_config_set
244
- begin
245
- assert_equal "OK", r.config(:set, "timeout", 200)
246
- assert_equal "200", r.config(:get, "*")["timeout"]
247
-
248
- assert_equal "OK", r.config(:set, "timeout", 100)
249
- assert_equal "100", r.config(:get, "*")["timeout"]
250
- ensure
251
- r.config :set, "timeout", 300
252
- end
253
- end
254
-
255
- driver(:ruby, :hiredis) do
256
- def test_consistency_on_multithreaded_env
257
- t = nil
258
-
259
- commands = {
260
- :set => lambda { |key, value| t.kill; "+OK\r\n" },
261
- :incr => lambda { |key| ":1\r\n" },
262
- }
263
-
264
- redis_mock(commands) do |redis|
265
- t = Thread.new do
266
- redis.set("foo", "bar")
267
- end
268
-
269
- t.join
270
-
271
- assert_equal 1, redis.incr("baz")
272
- end
273
- end
274
- end
275
- end
@@ -1,57 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestConnection < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_provides_a_meaningful_inspect
8
- assert_equal "#<Redis client v#{Redis::VERSION} for redis://127.0.0.1:#{PORT}/15>", r.inspect
9
- end
10
-
11
- def test_connection_information
12
- assert_equal "127.0.0.1", r.connection.fetch(:host)
13
- assert_equal 6381, r.connection.fetch(:port)
14
- assert_equal 15, r.connection.fetch(:db)
15
- assert_equal "127.0.0.1:6381", r.connection.fetch(:location)
16
- assert_equal "redis://127.0.0.1:6381/15", r.connection.fetch(:id)
17
- end
18
-
19
- def test_default_id_with_host_and_port
20
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0))
21
- assert_equal "redis://host:1234/0", redis.connection.fetch(:id)
22
- end
23
-
24
- def test_default_id_with_host_and_port_and_explicit_scheme
25
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0, :scheme => "foo"))
26
- assert_equal "redis://host:1234/0", redis.connection.fetch(:id)
27
- end
28
-
29
- def test_default_id_with_path
30
- redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0))
31
- assert_equal "redis:///tmp/redis.sock/0", redis.connection.fetch(:id)
32
- end
33
-
34
- def test_default_id_with_path_and_explicit_scheme
35
- redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0, :scheme => "foo"))
36
- assert_equal "redis:///tmp/redis.sock/0", redis.connection.fetch(:id)
37
- end
38
-
39
- def test_override_id
40
- redis = Redis.new(OPTIONS.merge(:id => "test"))
41
- assert_equal "test", redis.connection.fetch(:id)
42
- end
43
-
44
- def test_id_inside_multi
45
- redis = Redis.new(OPTIONS)
46
- id = nil
47
- connection_id = nil
48
-
49
- redis.multi do
50
- id = redis.id
51
- connection_id = redis.connection.fetch(:id)
52
- end
53
-
54
- assert_equal "redis://127.0.0.1:6381/15", id
55
- assert_equal "redis://127.0.0.1:6381/15", connection_id
56
- end
57
- end
data/test/db/.gitkeep DELETED
File without changes