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,68 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestDistributedInternals < Test::Unit::TestCase
4
-
5
- include Helper::Distributed
6
-
7
- def test_provides_a_meaningful_inspect
8
- nodes = ["redis://127.0.0.1:#{PORT}/15", *NODES]
9
- redis = Redis::Distributed.new nodes
10
-
11
- assert_equal "#<Redis client v#{Redis::VERSION} for #{redis.nodes.map(&:id).join(', ')}>", redis.inspect
12
- end
13
-
14
- def test_default_as_urls
15
- nodes = ["redis://127.0.0.1:#{PORT}/15", *NODES]
16
- redis = Redis::Distributed.new nodes
17
- assert_equal ["redis://127.0.0.1:#{PORT}/15", *NODES], redis.nodes.map { |node| node._client.id }
18
- end
19
-
20
- def test_default_as_config_hashes
21
- nodes = [OPTIONS.merge(:host => '127.0.0.1'), OPTIONS.merge(:host => 'somehost', :port => PORT.next)]
22
- redis = Redis::Distributed.new nodes
23
- assert_equal ["redis://127.0.0.1:#{PORT}/15","redis://somehost:#{PORT.next}/15"], redis.nodes.map { |node| node._client.id }
24
- end
25
-
26
- def test_as_mix_and_match
27
- nodes = ["redis://127.0.0.1:7389/15", OPTIONS.merge(:host => 'somehost'), OPTIONS.merge(:host => 'somehost', :port => PORT.next)]
28
- redis = Redis::Distributed.new nodes
29
- assert_equal ["redis://127.0.0.1:7389/15", "redis://somehost:#{PORT}/15", "redis://somehost:#{PORT.next}/15"], redis.nodes.map { |node| node._client.id }
30
- end
31
-
32
- def test_override_id
33
- nodes = [OPTIONS.merge(:host => '127.0.0.1', :id => "test"), OPTIONS.merge( :host => 'somehost', :port => PORT.next, :id => "test1")]
34
- redis = Redis::Distributed.new nodes
35
- assert_equal redis.nodes.first._client.id, "test"
36
- assert_equal redis.nodes.last._client.id, "test1"
37
- assert_equal "#<Redis client v#{Redis::VERSION} for #{redis.nodes.map(&:id).join(', ')}>", redis.inspect
38
- end
39
-
40
- def test_can_be_duped_to_create_a_new_connection
41
- redis = Redis::Distributed.new(NODES)
42
-
43
- clients = redis.info[0]["connected_clients"].to_i
44
-
45
- r2 = redis.dup
46
- r2.ping
47
-
48
- assert_equal clients + 1, redis.info[0]["connected_clients"].to_i
49
- end
50
-
51
- def test_keeps_options_after_dup
52
- r1 = Redis::Distributed.new(NODES, :tag => /^(\w+):/)
53
-
54
- assert_raise(Redis::Distributed::CannotDistribute) do
55
- r1.sinter("foo", "bar")
56
- end
57
-
58
- assert_equal [], r1.sinter("baz:foo", "baz:bar")
59
-
60
- r2 = r1.dup
61
-
62
- assert_raise(Redis::Distributed::CannotDistribute) do
63
- r2.sinter("foo", "bar")
64
- end
65
-
66
- assert_equal [], r2.sinter("baz:foo", "baz:bar")
67
- end
68
- end
@@ -1,50 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestDistributedKeyTags < Test::Unit::TestCase
4
-
5
- include Helper
6
- include Helper::Distributed
7
-
8
- def test_hashes_consistently
9
- r1 = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
10
- r2 = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
11
- r3 = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
12
-
13
- assert_equal r1.node_for("foo").id, r2.node_for("foo").id
14
- assert_equal r1.node_for("foo").id, r3.node_for("foo").id
15
- end
16
-
17
- def test_allows_clustering_of_keys
18
- r = Redis::Distributed.new(NODES)
19
- r.add_node("redis://127.0.0.1:#{PORT}/14")
20
- r.flushdb
21
-
22
- 100.times do |i|
23
- r.set "{foo}users:#{i}", i
24
- end
25
-
26
- assert_equal [0, 100], r.nodes.map { |node| node.keys.size }
27
- end
28
-
29
- def test_distributes_keys_if_no_clustering_is_used
30
- r.add_node("redis://127.0.0.1:#{PORT}/14")
31
- r.flushdb
32
-
33
- r.set "users:1", 1
34
- r.set "users:4", 4
35
-
36
- assert_equal [1, 1], r.nodes.map { |node| node.keys.size }
37
- end
38
-
39
- def test_allows_passing_a_custom_tag_extractor
40
- r = Redis::Distributed.new(NODES, :tag => /^(.+?):/)
41
- r.add_node("redis://127.0.0.1:#{PORT}/14")
42
- r.flushdb
43
-
44
- 100.times do |i|
45
- r.set "foo:users:#{i}", i
46
- end
47
-
48
- assert_equal [0, 100], r.nodes.map { |node| node.keys.size }
49
- end
50
- end
@@ -1,24 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestDistributedPersistenceControlCommands < Test::Unit::TestCase
4
-
5
- include Helper::Distributed
6
-
7
- def test_save
8
- redis_mock(:save => lambda { "+SAVE" }) do |redis|
9
- assert_equal ["SAVE"], redis.save
10
- end
11
- end
12
-
13
- def test_bgsave
14
- redis_mock(:bgsave => lambda { "+BGSAVE" }) do |redis|
15
- assert_equal ["BGSAVE"], redis.bgsave
16
- end
17
- end
18
-
19
- def test_lastsave
20
- redis_mock(:lastsave => lambda { "+LASTSAVE" }) do |redis|
21
- assert_equal ["LASTSAVE"], redis.lastsave
22
- end
23
- end
24
- end
@@ -1,90 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestDistributedPublishSubscribe < Test::Unit::TestCase
4
-
5
- include Helper::Distributed
6
-
7
- def test_subscribe_and_unsubscribe
8
- assert_raise Redis::Distributed::CannotDistribute do
9
- r.subscribe("foo", "bar") { }
10
- end
11
-
12
- assert_raise Redis::Distributed::CannotDistribute do
13
- r.subscribe("{qux}foo", "bar") { }
14
- end
15
- end
16
-
17
- def test_subscribe_and_unsubscribe_with_tags
18
- @subscribed = false
19
- @unsubscribed = false
20
-
21
- wire = Wire.new do
22
- r.subscribe("foo") do |on|
23
- on.subscribe do |channel, total|
24
- @subscribed = true
25
- @t1 = total
26
- end
27
-
28
- on.message do |channel, message|
29
- if message == "s1"
30
- r.unsubscribe
31
- @message = message
32
- end
33
- end
34
-
35
- on.unsubscribe do |channel, total|
36
- @unsubscribed = true
37
- @t2 = total
38
- end
39
- end
40
- end
41
-
42
- # Wait until the subscription is active before publishing
43
- Wire.pass while !@subscribed
44
-
45
- Redis::Distributed.new(NODES).publish("foo", "s1")
46
-
47
- wire.join
48
-
49
- assert @subscribed
50
- assert_equal 1, @t1
51
- assert @unsubscribed
52
- assert_equal 0, @t2
53
- assert_equal "s1", @message
54
- end
55
-
56
- def test_subscribe_within_subscribe
57
- @channels = []
58
-
59
- wire = Wire.new do
60
- r.subscribe("foo") do |on|
61
- on.subscribe do |channel, total|
62
- @channels << channel
63
-
64
- r.subscribe("bar") if channel == "foo"
65
- r.unsubscribe if channel == "bar"
66
- end
67
- end
68
- end
69
-
70
- wire.join
71
-
72
- assert_equal ["foo", "bar"], @channels
73
- end
74
-
75
- def test_other_commands_within_a_subscribe
76
- assert_raise Redis::CommandError do
77
- r.subscribe("foo") do |on|
78
- on.subscribe do |channel, total|
79
- r.set("bar", "s2")
80
- end
81
- end
82
- end
83
- end
84
-
85
- def test_subscribe_without_a_block
86
- assert_raise LocalJumpError do
87
- r.subscribe("foo")
88
- end
89
- end
90
- end
@@ -1,64 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestDistributedRemoteServerControlCommands < Test::Unit::TestCase
4
-
5
- include Helper::Distributed
6
-
7
- def test_info
8
- keys = [
9
- "redis_version",
10
- "uptime_in_seconds",
11
- "uptime_in_days",
12
- "connected_clients",
13
- "used_memory",
14
- "total_connections_received",
15
- "total_commands_processed",
16
- ]
17
-
18
- infos = r.info
19
-
20
- infos.each do |info|
21
- keys.each do |k|
22
- msg = "expected #info to include #{k}"
23
- assert info.keys.include?(k), msg
24
- end
25
- end
26
- end
27
-
28
- def test_info_commandstats
29
- target_version "2.5.7" do
30
- r.nodes.each { |n| n.config(:resetstat) }
31
- r.ping # Executed on every node
32
-
33
- r.info(:commandstats).each do |info|
34
- assert_equal "1", info["ping"]["calls"]
35
- end
36
- end
37
- end
38
-
39
- def test_monitor
40
- begin
41
- r.monitor
42
- rescue Exception => ex
43
- ensure
44
- assert ex.kind_of?(NotImplementedError)
45
- end
46
- end
47
-
48
- def test_echo
49
- assert_equal ["foo bar baz\n"], r.echo("foo bar baz\n")
50
- end
51
-
52
- def test_time
53
- target_version "2.5.4" do
54
- # Test that the difference between the time that Ruby reports and the time
55
- # that Redis reports is minimal (prevents the test from being racy).
56
- r.time.each do |rv|
57
- redis_usec = rv[0] * 1_000_000 + rv[1]
58
- ruby_usec = Integer(Time.now.to_f * 1_000_000)
59
-
60
- assert 500_000 > (ruby_usec - redis_usec).abs
61
- end
62
- end
63
- end
64
- end
@@ -1,100 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestDistributedScripting < Test::Unit::TestCase
4
-
5
- include Helper::Distributed
6
-
7
- def to_sha(script)
8
- r.script(:load, script).first
9
- end
10
-
11
- def test_script_exists
12
- target_version "2.5.9" do # 2.6-rc1
13
- a = to_sha("return 1")
14
- b = a.succ
15
-
16
- assert_equal [true], r.script(:exists, a)
17
- assert_equal [false], r.script(:exists, b)
18
- assert_equal [[true]], r.script(:exists, [a])
19
- assert_equal [[false]], r.script(:exists, [b])
20
- assert_equal [[true, false]], r.script(:exists, [a, b])
21
- end
22
- end
23
-
24
- def test_script_flush
25
- target_version "2.5.9" do # 2.6-rc1
26
- sha = to_sha("return 1")
27
- assert r.script(:exists, sha).first
28
- assert_equal ["OK"], r.script(:flush)
29
- assert !r.script(:exists, sha).first
30
- end
31
- end
32
-
33
- def test_script_kill
34
- target_version "2.5.9" do # 2.6-rc1
35
- redis_mock(:script => lambda { |arg| "+#{arg.upcase}" }) do |redis|
36
- assert_equal ["KILL"], redis.script(:kill)
37
- end
38
- end
39
- end
40
-
41
- def test_eval
42
- target_version "2.5.9" do # 2.6-rc1
43
- assert_raises(Redis::Distributed::CannotDistribute) do
44
- r.eval("return #KEYS")
45
- end
46
-
47
- assert_raises(Redis::Distributed::CannotDistribute) do
48
- r.eval("return KEYS", ["k1", "k2"])
49
- end
50
-
51
- assert_equal ["k1"], r.eval("return KEYS", ["k1"])
52
- assert_equal ["a1", "a2"], r.eval("return ARGV", ["k1"], ["a1", "a2"])
53
- end
54
- end
55
-
56
- def test_eval_with_options_hash
57
- target_version "2.5.9" do # 2.6-rc1
58
- assert_raises(Redis::Distributed::CannotDistribute) do
59
- r.eval("return #KEYS", {})
60
- end
61
-
62
- assert_raises(Redis::Distributed::CannotDistribute) do
63
- r.eval("return KEYS", { :keys => ["k1", "k2"] })
64
- end
65
-
66
- assert_equal ["k1"], r.eval("return KEYS", { :keys => ["k1"] })
67
- assert_equal ["a1", "a2"], r.eval("return ARGV", { :keys => ["k1"], :argv => ["a1", "a2"] })
68
- end
69
- end
70
-
71
- def test_evalsha
72
- target_version "2.5.9" do # 2.6-rc1
73
- assert_raises(Redis::Distributed::CannotDistribute) do
74
- r.evalsha(to_sha("return #KEYS"))
75
- end
76
-
77
- assert_raises(Redis::Distributed::CannotDistribute) do
78
- r.evalsha(to_sha("return KEYS"), ["k1", "k2"])
79
- end
80
-
81
- assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), ["k1"])
82
- assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), ["k1"], ["a1", "a2"])
83
- end
84
- end
85
-
86
- def test_evalsha_with_options_hash
87
- target_version "2.5.9" do # 2.6-rc1
88
- assert_raises(Redis::Distributed::CannotDistribute) do
89
- r.evalsha(to_sha("return #KEYS"), {})
90
- end
91
-
92
- assert_raises(Redis::Distributed::CannotDistribute) do
93
- r.evalsha(to_sha("return KEYS"), { :keys => ["k1", "k2"] })
94
- end
95
-
96
- assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), { :keys => ["k1"] })
97
- assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), { :keys => ["k1"], :argv => ["a1", "a2"] })
98
- end
99
- end
100
- end
@@ -1,18 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestDistributedSorting < Test::Unit::TestCase
4
-
5
- include Helper::Distributed
6
-
7
- def test_sort
8
- assert_raise(Redis::Distributed::CannotDistribute) do
9
- r.set("foo:1", "s1")
10
- r.set("foo:2", "s2")
11
-
12
- r.rpush("bar", "1")
13
- r.rpush("bar", "2")
14
-
15
- r.sort("bar", :get => "foo:*", :limit => [0, 1])
16
- end
17
- end
18
- end
@@ -1,56 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestDistributed < Test::Unit::TestCase
4
-
5
- include Helper::Distributed
6
-
7
- def test_handle_multiple_servers
8
- @r = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
9
-
10
- 100.times do |idx|
11
- @r.set(idx.to_s, "foo#{idx}")
12
- end
13
-
14
- 100.times do |idx|
15
- assert_equal "foo#{idx}", @r.get(idx.to_s)
16
- end
17
-
18
- assert_equal "0", @r.keys("*").sort.first
19
- assert_equal "string", @r.type("1")
20
- end
21
-
22
- def test_add_nodes
23
- logger = Logger.new("/dev/null")
24
-
25
- @r = Redis::Distributed.new NODES, :logger => logger, :timeout => 10
26
-
27
- assert_equal "127.0.0.1", @r.nodes[0]._client.host
28
- assert_equal PORT, @r.nodes[0]._client.port
29
- assert_equal 15, @r.nodes[0]._client.db
30
- assert_equal 10, @r.nodes[0]._client.timeout
31
- assert_equal logger, @r.nodes[0]._client.logger
32
-
33
- @r.add_node("redis://127.0.0.1:6380/14")
34
-
35
- assert_equal "127.0.0.1", @r.nodes[1]._client.host
36
- assert_equal 6380, @r.nodes[1]._client.port
37
- assert_equal 14, @r.nodes[1]._client.db
38
- assert_equal 10, @r.nodes[1]._client.timeout
39
- assert_equal logger, @r.nodes[1]._client.logger
40
- end
41
-
42
- def test_pipelining_commands_cannot_be_distributed
43
- assert_raise Redis::Distributed::CannotDistribute do
44
- r.pipelined do
45
- r.lpush "foo", "s1"
46
- r.lpush "foo", "s2"
47
- end
48
- end
49
- end
50
-
51
- def test_unknown_commands_does_not_work_by_default
52
- assert_raise NoMethodError do
53
- r.not_yet_implemented_command
54
- end
55
- end
56
- end
@@ -1,30 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestDistributedTransactions < Test::Unit::TestCase
4
-
5
- include Helper::Distributed
6
-
7
- def test_multi_discard
8
- @foo = nil
9
-
10
- assert_raise Redis::Distributed::CannotDistribute do
11
- r.multi { @foo = 1 }
12
- end
13
-
14
- assert_equal nil, @foo
15
-
16
- assert_raise Redis::Distributed::CannotDistribute do
17
- r.discard
18
- end
19
- end
20
-
21
- def test_watch_unwatch
22
- assert_raise Redis::Distributed::CannotDistribute do
23
- r.watch("foo")
24
- end
25
-
26
- assert_raise Redis::Distributed::CannotDistribute do
27
- r.unwatch
28
- end
29
- end
30
- end
@@ -1,14 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestEncoding < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_returns_properly_encoded_strings
8
- with_external_encoding("UTF-8") do
9
- r.set "foo", "שלום"
10
-
11
- assert_equal "Shalom שלום", "Shalom " + r.get("foo")
12
- end
13
- end
14
- end
@@ -1,57 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestErrorReplies < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- # Every test shouldn't disconnect from the server. Also, when error replies are
8
- # in play, the protocol should never get into an invalid state where there are
9
- # pending replies in the connection. Calling INFO after every test ensures that
10
- # the protocol is still in a valid state.
11
- def with_reconnection_check
12
- before = r.info["total_connections_received"]
13
- yield(r)
14
- after = r.info["total_connections_received"]
15
- ensure
16
- assert_equal before, after
17
- end
18
-
19
- def test_error_reply_for_single_command
20
- with_reconnection_check do
21
- begin
22
- r.unknown_command
23
- rescue => ex
24
- ensure
25
- assert ex.message =~ /unknown command/i
26
- end
27
- end
28
- end
29
-
30
- def test_raise_first_error_reply_in_pipeline
31
- with_reconnection_check do
32
- begin
33
- r.pipelined do
34
- r.set("foo", "s1")
35
- r.incr("foo") # not an integer
36
- r.lpush("foo", "value") # wrong kind of value
37
- end
38
- rescue => ex
39
- ensure
40
- assert ex.message =~ /not an integer/i
41
- end
42
- end
43
- end
44
-
45
- def test_recover_from_raise_in__call_loop
46
- with_reconnection_check do
47
- begin
48
- r._client.call_loop([:invalid_monitor]) do
49
- assert false # Should never be executed
50
- end
51
- rescue => ex
52
- ensure
53
- assert ex.message =~ /unknown command/i
54
- end
55
- end
56
- end
57
- end
@@ -1,60 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestForkSafety < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- driver(:ruby, :hiredis) do
8
- def test_fork_safety
9
- redis = Redis.new(OPTIONS)
10
- redis.set "foo", 1
11
-
12
- child_pid = fork do
13
- begin
14
- # InheritedError triggers a reconnect,
15
- # so we need to disable reconnects to force
16
- # the exception bubble up
17
- redis.without_reconnect do
18
- redis.set "foo", 2
19
- end
20
- rescue Redis::InheritedError
21
- exit 127
22
- end
23
- end
24
-
25
- _, status = Process.wait2(child_pid)
26
-
27
- assert_equal 127, status.exitstatus
28
- assert_equal "1", redis.get("foo")
29
-
30
- rescue NotImplementedError => error
31
- raise unless error.message =~ /fork is not available/
32
- end
33
-
34
- def test_fork_safety_with_enabled_inherited_socket
35
- redis = Redis.new(OPTIONS.merge(:inherit_socket => true))
36
- redis.set "foo", 1
37
-
38
- child_pid = fork do
39
- begin
40
- # InheritedError triggers a reconnect,
41
- # so we need to disable reconnects to force
42
- # the exception bubble up
43
- redis.without_reconnect do
44
- redis.set "foo", 2
45
- end
46
- rescue Redis::InheritedError
47
- exit 127
48
- end
49
- end
50
-
51
- _, status = Process.wait2(child_pid)
52
-
53
- assert_equal 0, status.exitstatus
54
- assert_equal "2", redis.get("foo")
55
-
56
- rescue NotImplementedError => error
57
- raise unless error.message =~ /fork is not available/
58
- end
59
- end
60
- end