redis 3.3.5 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +32 -50
  3. data/CHANGELOG.md +7 -9
  4. data/Gemfile +0 -1
  5. data/README.md +31 -75
  6. data/benchmarking/logging.rb +1 -1
  7. data/lib/redis.rb +31 -35
  8. data/lib/redis/client.rb +13 -8
  9. data/lib/redis/connection.rb +2 -2
  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 +7 -27
  13. data/lib/redis/connection/synchrony.rb +3 -3
  14. data/lib/redis/pipeline.rb +0 -6
  15. data/lib/redis/version.rb +1 -1
  16. data/makefile +42 -0
  17. data/redis.gemspec +4 -8
  18. data/test/bitpos_test.rb +13 -19
  19. data/test/blocking_commands_test.rb +147 -6
  20. data/test/client_test.rb +1 -1
  21. data/test/command_map_test.rb +3 -5
  22. data/test/commands_on_hashes_test.rb +158 -5
  23. data/test/commands_on_hyper_log_log_test.rb +55 -6
  24. data/test/commands_on_lists_test.rb +139 -5
  25. data/test/commands_on_sets_test.rb +136 -5
  26. data/test/commands_on_sorted_sets_test.rb +312 -5
  27. data/test/commands_on_strings_test.rb +243 -6
  28. data/test/commands_on_value_types_test.rb +120 -7
  29. data/test/connection_handling_test.rb +5 -7
  30. data/test/encoding_test.rb +4 -8
  31. data/test/error_replies_test.rb +2 -4
  32. data/test/fork_safety_test.rb +1 -6
  33. data/test/helper.rb +9 -62
  34. data/test/helper_test.rb +1 -3
  35. data/test/internals_test.rb +67 -49
  36. data/test/persistence_control_commands_test.rb +1 -3
  37. data/test/pipelining_commands_test.rb +4 -8
  38. data/test/publish_subscribe_test.rb +1 -3
  39. data/test/remote_server_control_commands_test.rb +61 -4
  40. data/test/scanning_test.rb +1 -7
  41. data/test/scripting_test.rb +1 -3
  42. data/test/sentinel_command_test.rb +1 -3
  43. data/test/sentinel_test.rb +1 -3
  44. data/test/sorting_test.rb +1 -3
  45. data/test/ssl_test.rb +45 -49
  46. data/test/support/connection/hiredis.rb +1 -1
  47. data/test/support/connection/ruby.rb +1 -1
  48. data/test/support/connection/synchrony.rb +1 -1
  49. data/test/synchrony_driver.rb +6 -9
  50. data/test/thread_safety_test.rb +1 -3
  51. data/test/transactions_test.rb +1 -3
  52. data/test/unknown_commands_test.rb +1 -3
  53. data/test/url_param_test.rb +44 -46
  54. metadata +31 -77
  55. data/Rakefile +0 -87
  56. data/examples/dist_redis.rb +0 -43
  57. data/lib/redis/distributed.rb +0 -873
  58. data/lib/redis/hash_ring.rb +0 -132
  59. data/test/connection_test.rb +0 -57
  60. data/test/distributed_blocking_commands_test.rb +0 -46
  61. data/test/distributed_commands_on_hashes_test.rb +0 -10
  62. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  63. data/test/distributed_commands_on_lists_test.rb +0 -22
  64. data/test/distributed_commands_on_sets_test.rb +0 -83
  65. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  66. data/test/distributed_commands_on_strings_test.rb +0 -59
  67. data/test/distributed_commands_on_value_types_test.rb +0 -95
  68. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  69. data/test/distributed_connection_handling_test.rb +0 -23
  70. data/test/distributed_internals_test.rb +0 -79
  71. data/test/distributed_key_tags_test.rb +0 -52
  72. data/test/distributed_persistence_control_commands_test.rb +0 -26
  73. data/test/distributed_publish_subscribe_test.rb +0 -92
  74. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  75. data/test/distributed_scripting_test.rb +0 -102
  76. data/test/distributed_sorting_test.rb +0 -20
  77. data/test/distributed_test.rb +0 -58
  78. data/test/distributed_transactions_test.rb +0 -32
  79. data/test/lint/blocking_commands.rb +0 -150
  80. data/test/lint/hashes.rb +0 -162
  81. data/test/lint/hyper_log_log.rb +0 -60
  82. data/test/lint/lists.rb +0 -143
  83. data/test/lint/sets.rb +0 -140
  84. data/test/lint/sorted_sets.rb +0 -316
  85. data/test/lint/strings.rb +0 -260
  86. data/test/lint/value_types.rb +0 -122
@@ -1,95 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/value_types"
5
-
6
- class TestDistributedCommandsOnValueTypes < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::ValueTypes
10
-
11
- def test_del
12
- r.set "foo", "s1"
13
- r.set "bar", "s2"
14
- r.set "baz", "s3"
15
-
16
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
17
-
18
- assert_equal 1, r.del("foo")
19
-
20
- assert_equal ["bar", "baz"], r.keys("*").sort
21
-
22
- assert_equal 2, r.del("bar", "baz")
23
-
24
- assert_equal [], r.keys("*").sort
25
- end
26
-
27
- def test_del_with_array_argument
28
- r.set "foo", "s1"
29
- r.set "bar", "s2"
30
- r.set "baz", "s3"
31
-
32
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
33
-
34
- assert_equal 1, r.del(["foo"])
35
-
36
- assert_equal ["bar", "baz"], r.keys("*").sort
37
-
38
- assert_equal 2, r.del(["bar", "baz"])
39
-
40
- assert_equal [], r.keys("*").sort
41
- end
42
-
43
- def test_randomkey
44
- assert_raise Redis::Distributed::CannotDistribute do
45
- r.randomkey
46
- end
47
- end
48
-
49
- def test_rename
50
- assert_raise Redis::Distributed::CannotDistribute do
51
- r.set("foo", "s1")
52
- r.rename "foo", "bar"
53
- end
54
-
55
- assert_equal "s1", r.get("foo")
56
- assert_equal nil, r.get("bar")
57
- end
58
-
59
- def test_renamenx
60
- assert_raise Redis::Distributed::CannotDistribute do
61
- r.set("foo", "s1")
62
- r.rename "foo", "bar"
63
- end
64
-
65
- assert_equal "s1", r.get("foo")
66
- assert_equal nil , r.get("bar")
67
- end
68
-
69
- def test_dbsize
70
- assert_equal [0], r.dbsize
71
-
72
- r.set("foo", "s1")
73
-
74
- assert_equal [1], r.dbsize
75
- end
76
-
77
- def test_flushdb
78
- r.set("foo", "s1")
79
- r.set("bar", "s2")
80
-
81
- assert_equal [2], r.dbsize
82
-
83
- r.flushdb
84
-
85
- assert_equal [0], r.dbsize
86
- end
87
-
88
- def test_migrate
89
- r.set("foo", "s1")
90
-
91
- assert_raise Redis::Distributed::CannotDistribute do
92
- r.migrate("foo", {})
93
- end
94
- end
95
- end
@@ -1,164 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestDistributedCommandsRequiringClustering < Test::Unit::TestCase
6
-
7
- include Helper::Distributed
8
-
9
- def test_rename
10
- r.set("{qux}foo", "s1")
11
- r.rename "{qux}foo", "{qux}bar"
12
-
13
- assert_equal "s1", r.get("{qux}bar")
14
- assert_equal nil, r.get("{qux}foo")
15
- end
16
-
17
- def test_renamenx
18
- r.set("{qux}foo", "s1")
19
- r.set("{qux}bar", "s2")
20
-
21
- assert_equal false, r.renamenx("{qux}foo", "{qux}bar")
22
-
23
- assert_equal "s1", r.get("{qux}foo")
24
- assert_equal "s2", r.get("{qux}bar")
25
- end
26
-
27
- def test_brpoplpush
28
- r.rpush "{qux}foo", "s1"
29
- r.rpush "{qux}foo", "s2"
30
-
31
- assert_equal "s2", r.brpoplpush("{qux}foo", "{qux}bar", :timeout => 1)
32
- assert_equal ["s2"], r.lrange("{qux}bar", 0, -1)
33
- end
34
-
35
- def test_rpoplpush
36
- r.rpush "{qux}foo", "s1"
37
- r.rpush "{qux}foo", "s2"
38
-
39
- assert_equal "s2", r.rpoplpush("{qux}foo", "{qux}bar")
40
- assert_equal ["s2"], r.lrange("{qux}bar", 0, -1)
41
- assert_equal "s1", r.rpoplpush("{qux}foo", "{qux}bar")
42
- assert_equal ["s1", "s2"], r.lrange("{qux}bar", 0, -1)
43
- end
44
-
45
- def test_smove
46
- r.sadd "{qux}foo", "s1"
47
- r.sadd "{qux}bar", "s2"
48
-
49
- assert r.smove("{qux}foo", "{qux}bar", "s1")
50
- assert r.sismember("{qux}bar", "s1")
51
- end
52
-
53
- def test_sinter
54
- r.sadd "{qux}foo", "s1"
55
- r.sadd "{qux}foo", "s2"
56
- r.sadd "{qux}bar", "s2"
57
-
58
- assert_equal ["s2"], r.sinter("{qux}foo", "{qux}bar")
59
- end
60
-
61
- def test_sinterstore
62
- r.sadd "{qux}foo", "s1"
63
- r.sadd "{qux}foo", "s2"
64
- r.sadd "{qux}bar", "s2"
65
-
66
- r.sinterstore("{qux}baz", "{qux}foo", "{qux}bar")
67
-
68
- assert_equal ["s2"], r.smembers("{qux}baz")
69
- end
70
-
71
- def test_sunion
72
- r.sadd "{qux}foo", "s1"
73
- r.sadd "{qux}foo", "s2"
74
- r.sadd "{qux}bar", "s2"
75
- r.sadd "{qux}bar", "s3"
76
-
77
- assert_equal ["s1", "s2", "s3"], r.sunion("{qux}foo", "{qux}bar").sort
78
- end
79
-
80
- def test_sunionstore
81
- r.sadd "{qux}foo", "s1"
82
- r.sadd "{qux}foo", "s2"
83
- r.sadd "{qux}bar", "s2"
84
- r.sadd "{qux}bar", "s3"
85
-
86
- r.sunionstore("{qux}baz", "{qux}foo", "{qux}bar")
87
-
88
- assert_equal ["s1", "s2", "s3"], r.smembers("{qux}baz").sort
89
- end
90
-
91
- def test_sdiff
92
- r.sadd "{qux}foo", "s1"
93
- r.sadd "{qux}foo", "s2"
94
- r.sadd "{qux}bar", "s2"
95
- r.sadd "{qux}bar", "s3"
96
-
97
- assert_equal ["s1"], r.sdiff("{qux}foo", "{qux}bar")
98
- assert_equal ["s3"], r.sdiff("{qux}bar", "{qux}foo")
99
- end
100
-
101
- def test_sdiffstore
102
- r.sadd "{qux}foo", "s1"
103
- r.sadd "{qux}foo", "s2"
104
- r.sadd "{qux}bar", "s2"
105
- r.sadd "{qux}bar", "s3"
106
-
107
- r.sdiffstore("{qux}baz", "{qux}foo", "{qux}bar")
108
-
109
- assert_equal ["s1"], r.smembers("{qux}baz")
110
- end
111
-
112
- def test_sort
113
- r.set("{qux}foo:1", "s1")
114
- r.set("{qux}foo:2", "s2")
115
-
116
- r.rpush("{qux}bar", "1")
117
- r.rpush("{qux}bar", "2")
118
-
119
- assert_equal ["s1"], r.sort("{qux}bar", :get => "{qux}foo:*", :limit => [0, 1])
120
- assert_equal ["s2"], r.sort("{qux}bar", :get => "{qux}foo:*", :limit => [0, 1], :order => "desc alpha")
121
- end
122
-
123
- def test_sort_with_an_array_of_gets
124
- r.set("{qux}foo:1:a", "s1a")
125
- r.set("{qux}foo:1:b", "s1b")
126
-
127
- r.set("{qux}foo:2:a", "s2a")
128
- r.set("{qux}foo:2:b", "s2b")
129
-
130
- r.rpush("{qux}bar", "1")
131
- r.rpush("{qux}bar", "2")
132
-
133
- assert_equal [["s1a", "s1b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"], :limit => [0, 1])
134
- assert_equal [["s2a", "s2b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"], :limit => [0, 1], :order => "desc alpha")
135
- assert_equal [["s1a", "s1b"], ["s2a", "s2b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"])
136
- end
137
-
138
- def test_sort_with_store
139
- r.set("{qux}foo:1", "s1")
140
- r.set("{qux}foo:2", "s2")
141
-
142
- r.rpush("{qux}bar", "1")
143
- r.rpush("{qux}bar", "2")
144
-
145
- r.sort("{qux}bar", :get => "{qux}foo:*", :store => "{qux}baz")
146
- assert_equal ["s1", "s2"], r.lrange("{qux}baz", 0, -1)
147
- end
148
-
149
- def test_bitop
150
- target_version "2.5.10" do
151
- r.set("{qux}foo", "a")
152
- r.set("{qux}bar", "b")
153
-
154
- r.bitop(:and, "{qux}foo&bar", "{qux}foo", "{qux}bar")
155
- assert_equal "\x60", r.get("{qux}foo&bar")
156
- r.bitop(:or, "{qux}foo|bar", "{qux}foo", "{qux}bar")
157
- assert_equal "\x63", r.get("{qux}foo|bar")
158
- r.bitop(:xor, "{qux}foo^bar", "{qux}foo", "{qux}bar")
159
- assert_equal "\x03", r.get("{qux}foo^bar")
160
- r.bitop(:not, "{qux}~foo", "{qux}foo")
161
- assert_equal "\x9E", r.get("{qux}~foo")
162
- end
163
- end
164
- end
@@ -1,23 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestDistributedConnectionHandling < Test::Unit::TestCase
6
-
7
- include Helper::Distributed
8
-
9
- def test_ping
10
- assert_equal ["PONG"], r.ping
11
- end
12
-
13
- def test_select
14
- r.set "foo", "bar"
15
-
16
- r.select 14
17
- assert_equal nil, r.get("foo")
18
-
19
- r.select 15
20
-
21
- assert_equal "bar", r.get("foo")
22
- end
23
- end
@@ -1,79 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestDistributedInternals < Test::Unit::TestCase
6
-
7
- include Helper::Distributed
8
-
9
- def test_provides_a_meaningful_inspect
10
- nodes = ["redis://localhost:#{PORT}/15", *NODES]
11
- redis = Redis::Distributed.new nodes
12
-
13
- assert_equal "#<Redis client v#{Redis::VERSION} for #{redis.nodes.map(&:id).join(', ')}>", redis.inspect
14
- end
15
-
16
- def test_default_as_urls
17
- nodes = ["redis://localhost:#{PORT}/15", *NODES]
18
- redis = Redis::Distributed.new nodes
19
- assert_equal ["redis://localhost:#{PORT}/15", *NODES], redis.nodes.map { |node| node.client.id}
20
- end
21
-
22
- def test_default_as_config_hashes
23
- nodes = [OPTIONS.merge(:host => '127.0.0.1'), OPTIONS.merge(:host => 'somehost', :port => PORT.next)]
24
- redis = Redis::Distributed.new nodes
25
- assert_equal ["redis://127.0.0.1:#{PORT}/15","redis://somehost:#{PORT.next}/15"], redis.nodes.map { |node| node.client.id }
26
- end
27
-
28
- def test_as_mix_and_match
29
- nodes = ["redis://127.0.0.1:7389/15", OPTIONS.merge(:host => 'somehost'), OPTIONS.merge(:host => 'somehost', :port => PORT.next)]
30
- redis = Redis::Distributed.new nodes
31
- 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 }
32
- end
33
-
34
- def test_override_id
35
- nodes = [OPTIONS.merge(:host => '127.0.0.1', :id => "test"), OPTIONS.merge( :host => 'somehost', :port => PORT.next, :id => "test1")]
36
- redis = Redis::Distributed.new nodes
37
- assert_equal redis.nodes.first.client.id, "test"
38
- assert_equal redis.nodes.last.client.id, "test1"
39
- assert_equal "#<Redis client v#{Redis::VERSION} for #{redis.nodes.map(&:id).join(', ')}>", redis.inspect
40
- end
41
-
42
- def test_can_be_duped_to_create_a_new_connection
43
- redis = Redis::Distributed.new(NODES)
44
-
45
- clients = redis.info[0]["connected_clients"].to_i
46
-
47
- r2 = redis.dup
48
- r2.ping
49
-
50
- assert_equal clients + 1, redis.info[0]["connected_clients"].to_i
51
- end
52
-
53
- def test_keeps_options_after_dup
54
- r1 = Redis::Distributed.new(NODES, :tag => /^(\w+):/)
55
-
56
- assert_raise(Redis::Distributed::CannotDistribute) do
57
- r1.sinter("foo", "bar")
58
- end
59
-
60
- assert_equal [], r1.sinter("baz:foo", "baz:bar")
61
-
62
- r2 = r1.dup
63
-
64
- assert_raise(Redis::Distributed::CannotDistribute) do
65
- r2.sinter("foo", "bar")
66
- end
67
-
68
- assert_equal [], r2.sinter("baz:foo", "baz:bar")
69
- end
70
-
71
- def test_colliding_node_ids
72
- nodes = ["redis://localhost:#{PORT}/15", "redis://localhost:#{PORT}/15", *NODES]
73
-
74
- assert_raise(RuntimeError) do
75
- Redis::Distributed.new nodes
76
- end
77
- end
78
-
79
- end
@@ -1,52 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestDistributedKeyTags < Test::Unit::TestCase
6
-
7
- include Helper
8
- include Helper::Distributed
9
-
10
- def test_hashes_consistently
11
- r1 = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
12
- r2 = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
13
- r3 = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
14
-
15
- assert_equal r1.node_for("foo").id, r2.node_for("foo").id
16
- assert_equal r1.node_for("foo").id, r3.node_for("foo").id
17
- end
18
-
19
- def test_allows_clustering_of_keys
20
- r = Redis::Distributed.new(NODES)
21
- r.add_node("redis://127.0.0.1:#{PORT}/14")
22
- r.flushdb
23
-
24
- 100.times do |i|
25
- r.set "{foo}users:#{i}", i
26
- end
27
-
28
- assert_equal [0, 100], r.nodes.map { |node| node.keys.size }
29
- end
30
-
31
- def test_distributes_keys_if_no_clustering_is_used
32
- r.add_node("redis://127.0.0.1:#{PORT}/14")
33
- r.flushdb
34
-
35
- r.set "users:1", 1
36
- r.set "users:4", 4
37
-
38
- assert_equal [1, 1], r.nodes.map { |node| node.keys.size }
39
- end
40
-
41
- def test_allows_passing_a_custom_tag_extractor
42
- r = Redis::Distributed.new(NODES, :tag => /^(.+?):/)
43
- r.add_node("redis://127.0.0.1:#{PORT}/14")
44
- r.flushdb
45
-
46
- 100.times do |i|
47
- r.set "foo:users:#{i}", i
48
- end
49
-
50
- assert_equal [0, 100], r.nodes.map { |node| node.keys.size }
51
- end
52
- end
@@ -1,26 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestDistributedPersistenceControlCommands < Test::Unit::TestCase
6
-
7
- include Helper::Distributed
8
-
9
- def test_save
10
- redis_mock(:save => lambda { "+SAVE" }) do |redis|
11
- assert_equal ["SAVE"], redis.save
12
- end
13
- end
14
-
15
- def test_bgsave
16
- redis_mock(:bgsave => lambda { "+BGSAVE" }) do |redis|
17
- assert_equal ["BGSAVE"], redis.bgsave
18
- end
19
- end
20
-
21
- def test_lastsave
22
- redis_mock(:lastsave => lambda { "+LASTSAVE" }) do |redis|
23
- assert_equal ["LASTSAVE"], redis.lastsave
24
- end
25
- end
26
- end
@@ -1,92 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestDistributedPublishSubscribe < Test::Unit::TestCase
6
-
7
- include Helper::Distributed
8
-
9
- def test_subscribe_and_unsubscribe
10
- assert_raise Redis::Distributed::CannotDistribute do
11
- r.subscribe("foo", "bar") { }
12
- end
13
-
14
- assert_raise Redis::Distributed::CannotDistribute do
15
- r.subscribe("{qux}foo", "bar") { }
16
- end
17
- end
18
-
19
- def test_subscribe_and_unsubscribe_with_tags
20
- @subscribed = false
21
- @unsubscribed = false
22
-
23
- wire = Wire.new do
24
- r.subscribe("foo") do |on|
25
- on.subscribe do |channel, total|
26
- @subscribed = true
27
- @t1 = total
28
- end
29
-
30
- on.message do |channel, message|
31
- if message == "s1"
32
- r.unsubscribe
33
- @message = message
34
- end
35
- end
36
-
37
- on.unsubscribe do |channel, total|
38
- @unsubscribed = true
39
- @t2 = total
40
- end
41
- end
42
- end
43
-
44
- # Wait until the subscription is active before publishing
45
- Wire.pass while !@subscribed
46
-
47
- Redis::Distributed.new(NODES).publish("foo", "s1")
48
-
49
- wire.join
50
-
51
- assert @subscribed
52
- assert_equal 1, @t1
53
- assert @unsubscribed
54
- assert_equal 0, @t2
55
- assert_equal "s1", @message
56
- end
57
-
58
- def test_subscribe_within_subscribe
59
- @channels = []
60
-
61
- wire = Wire.new do
62
- r.subscribe("foo") do |on|
63
- on.subscribe do |channel, total|
64
- @channels << channel
65
-
66
- r.subscribe("bar") if channel == "foo"
67
- r.unsubscribe if channel == "bar"
68
- end
69
- end
70
- end
71
-
72
- wire.join
73
-
74
- assert_equal ["foo", "bar"], @channels
75
- end
76
-
77
- def test_other_commands_within_a_subscribe
78
- assert_raise Redis::CommandError do
79
- r.subscribe("foo") do |on|
80
- on.subscribe do |channel, total|
81
- r.set("bar", "s2")
82
- end
83
- end
84
- end
85
- end
86
-
87
- def test_subscribe_without_a_block
88
- assert_raise LocalJumpError do
89
- r.subscribe("foo")
90
- end
91
- end
92
- end