redis 3.0.0 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +269 -0
  3. data/README.md +295 -58
  4. data/lib/redis.rb +1760 -451
  5. data/lib/redis/client.rb +355 -88
  6. data/lib/redis/cluster.rb +295 -0
  7. data/lib/redis/cluster/command.rb +81 -0
  8. data/lib/redis/cluster/command_loader.rb +34 -0
  9. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  10. data/lib/redis/cluster/node.rb +107 -0
  11. data/lib/redis/cluster/node_key.rb +31 -0
  12. data/lib/redis/cluster/node_loader.rb +37 -0
  13. data/lib/redis/cluster/option.rb +90 -0
  14. data/lib/redis/cluster/slot.rb +86 -0
  15. data/lib/redis/cluster/slot_loader.rb +49 -0
  16. data/lib/redis/connection.rb +4 -2
  17. data/lib/redis/connection/command_helper.rb +5 -10
  18. data/lib/redis/connection/hiredis.rb +12 -8
  19. data/lib/redis/connection/registry.rb +2 -1
  20. data/lib/redis/connection/ruby.rb +232 -63
  21. data/lib/redis/connection/synchrony.rb +41 -14
  22. data/lib/redis/distributed.rb +205 -70
  23. data/lib/redis/errors.rb +48 -0
  24. data/lib/redis/hash_ring.rb +31 -73
  25. data/lib/redis/pipeline.rb +74 -18
  26. data/lib/redis/subscribe.rb +24 -13
  27. data/lib/redis/version.rb +3 -1
  28. metadata +63 -160
  29. data/.gitignore +0 -10
  30. data/.order +0 -169
  31. data/.travis.yml +0 -50
  32. data/.travis/Gemfile +0 -11
  33. data/.yardopts +0 -3
  34. data/Rakefile +0 -392
  35. data/benchmarking/logging.rb +0 -62
  36. data/benchmarking/pipeline.rb +0 -51
  37. data/benchmarking/speed.rb +0 -21
  38. data/benchmarking/suite.rb +0 -24
  39. data/benchmarking/worker.rb +0 -71
  40. data/examples/basic.rb +0 -15
  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 -31
  45. data/examples/sets.rb +0 -36
  46. data/examples/unicorn/config.ru +0 -3
  47. data/examples/unicorn/unicorn.rb +0 -20
  48. data/redis.gemspec +0 -41
  49. data/test/blocking_commands_test.rb +0 -42
  50. data/test/command_map_test.rb +0 -30
  51. data/test/commands_on_hashes_test.rb +0 -21
  52. data/test/commands_on_lists_test.rb +0 -20
  53. data/test/commands_on_sets_test.rb +0 -77
  54. data/test/commands_on_sorted_sets_test.rb +0 -109
  55. data/test/commands_on_strings_test.rb +0 -83
  56. data/test/commands_on_value_types_test.rb +0 -99
  57. data/test/connection_handling_test.rb +0 -189
  58. data/test/db/.gitignore +0 -1
  59. data/test/distributed_blocking_commands_test.rb +0 -46
  60. data/test/distributed_commands_on_hashes_test.rb +0 -10
  61. data/test/distributed_commands_on_lists_test.rb +0 -22
  62. data/test/distributed_commands_on_sets_test.rb +0 -83
  63. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  64. data/test/distributed_commands_on_strings_test.rb +0 -48
  65. data/test/distributed_commands_on_value_types_test.rb +0 -87
  66. data/test/distributed_commands_requiring_clustering_test.rb +0 -148
  67. data/test/distributed_connection_handling_test.rb +0 -23
  68. data/test/distributed_internals_test.rb +0 -15
  69. data/test/distributed_key_tags_test.rb +0 -52
  70. data/test/distributed_persistence_control_commands_test.rb +0 -26
  71. data/test/distributed_publish_subscribe_test.rb +0 -92
  72. data/test/distributed_remote_server_control_commands_test.rb +0 -53
  73. data/test/distributed_scripting_test.rb +0 -102
  74. data/test/distributed_sorting_test.rb +0 -20
  75. data/test/distributed_test.rb +0 -58
  76. data/test/distributed_transactions_test.rb +0 -32
  77. data/test/encoding_test.rb +0 -18
  78. data/test/error_replies_test.rb +0 -59
  79. data/test/helper.rb +0 -188
  80. data/test/helper_test.rb +0 -22
  81. data/test/internals_test.rb +0 -214
  82. data/test/lint/blocking_commands.rb +0 -124
  83. data/test/lint/hashes.rb +0 -162
  84. data/test/lint/lists.rb +0 -143
  85. data/test/lint/sets.rb +0 -96
  86. data/test/lint/sorted_sets.rb +0 -201
  87. data/test/lint/strings.rb +0 -157
  88. data/test/lint/value_types.rb +0 -106
  89. data/test/persistence_control_commands_test.rb +0 -26
  90. data/test/pipelining_commands_test.rb +0 -195
  91. data/test/publish_subscribe_test.rb +0 -153
  92. data/test/remote_server_control_commands_test.rb +0 -104
  93. data/test/scripting_test.rb +0 -78
  94. data/test/sorting_test.rb +0 -45
  95. data/test/support/connection/hiredis.rb +0 -1
  96. data/test/support/connection/ruby.rb +0 -1
  97. data/test/support/connection/synchrony.rb +0 -17
  98. data/test/support/redis_mock.rb +0 -92
  99. data/test/support/wire/synchrony.rb +0 -24
  100. data/test/support/wire/thread.rb +0 -5
  101. data/test/synchrony_driver.rb +0 -57
  102. data/test/test.conf +0 -9
  103. data/test/thread_safety_test.rb +0 -32
  104. data/test/transactions_test.rb +0 -244
  105. data/test/unknown_commands_test.rb +0 -14
  106. data/test/url_param_test.rb +0 -64
@@ -1,189 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require "helper"
4
-
5
- class TestConnectionHandling < Test::Unit::TestCase
6
-
7
- include Helper::Client
8
-
9
- def test_auth
10
- commands = {
11
- :auth => lambda { |password| $auth = password; "+OK" },
12
- :get => lambda { |key| $auth == "secret" ? "$3\r\nbar" : "$-1" },
13
- }
14
-
15
- redis_mock(commands, :password => "secret") do |redis|
16
- assert_equal "bar", redis.get("foo")
17
- end
18
- end
19
-
20
- def test_ping
21
- assert_equal "PONG", r.ping
22
- end
23
-
24
- def test_select
25
- r.set "foo", "bar"
26
-
27
- r.select 14
28
- assert_equal nil, r.get("foo")
29
-
30
- r.client.disconnect
31
-
32
- assert_equal nil, r.get("foo")
33
- end
34
-
35
- def test_quit
36
- r.quit
37
-
38
- assert !r.client.connected?
39
- end
40
-
41
- def test_shutdown
42
- commands = {
43
- :shutdown => lambda { :exit }
44
- }
45
-
46
- redis_mock(commands) do |redis|
47
- # SHUTDOWN does not reply: test that it does not raise here.
48
- assert_equal nil, redis.shutdown
49
- end
50
- end
51
-
52
- def test_shutdown_with_error
53
- connections = 0
54
- commands = {
55
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
56
- :connections => lambda { ":#{connections}\r\n" },
57
- :shutdown => lambda { "-ERR could not shutdown\r\n" }
58
- }
59
-
60
- redis_mock(commands) do |redis|
61
- connections = redis.connections
62
-
63
- # SHUTDOWN replies with an error: test that it gets raised
64
- assert_raise Redis::CommandError do
65
- redis.shutdown
66
- end
67
-
68
- # The connection should remain in tact
69
- assert_equal connections, redis.connections
70
- end
71
- end
72
-
73
- def test_shutdown_from_pipeline
74
- commands = {
75
- :shutdown => lambda { :exit }
76
- }
77
-
78
- redis_mock(commands) do |redis|
79
- result = redis.pipelined do
80
- redis.shutdown
81
- end
82
-
83
- assert_equal nil, result
84
- assert !redis.client.connected?
85
- end
86
- end
87
-
88
- def test_shutdown_with_error_from_pipeline
89
- connections = 0
90
- commands = {
91
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
92
- :connections => lambda { ":#{connections}\r\n" },
93
- :shutdown => lambda { "-ERR could not shutdown\r\n" }
94
- }
95
-
96
- redis_mock(commands) do |redis|
97
- connections = redis.connections
98
-
99
- # SHUTDOWN replies with an error: test that it gets raised
100
- assert_raise Redis::CommandError do
101
- redis.pipelined do
102
- redis.shutdown
103
- end
104
- end
105
-
106
- # The connection should remain in tact
107
- assert_equal connections, redis.connections
108
- end
109
- end
110
-
111
- def test_shutdown_from_multi_exec
112
- commands = {
113
- :multi => lambda { "+OK\r\n" },
114
- :shutdown => lambda { "+QUEUED\r\n" },
115
- :exec => lambda { :exit }
116
- }
117
-
118
- redis_mock(commands) do |redis|
119
- result = redis.multi do
120
- redis.shutdown
121
- end
122
-
123
- assert_equal nil, result
124
- assert !redis.client.connected?
125
- end
126
- end
127
-
128
- def test_shutdown_with_error_from_multi_exec
129
- connections = 0
130
- commands = {
131
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
132
- :connections => lambda { ":#{connections}\r\n" },
133
- :multi => lambda { "+OK\r\n" },
134
- :shutdown => lambda { "+QUEUED\r\n" },
135
- :exec => lambda { "*1\r\n-ERR could not shutdown\r\n" }
136
- }
137
-
138
- redis_mock(commands) do |redis|
139
- connections = redis.connections
140
-
141
- # SHUTDOWN replies with an error: test that it gets returned
142
- # We should test for Redis::CommandError here, but hiredis doesn't yet do
143
- # custom error classes.
144
- err = nil
145
-
146
- begin
147
- redis.multi { redis.shutdown }
148
- rescue => err
149
- end
150
-
151
- assert err.kind_of?(StandardError)
152
-
153
- # The connection should remain intact
154
- assert_equal connections, redis.connections
155
- end
156
- end
157
-
158
- def test_slaveof
159
- redis_mock(:slaveof => lambda { |host, port| "+SLAVEOF #{host} #{port}" }) do |redis|
160
- assert_equal "SLAVEOF localhost 6381", redis.slaveof("localhost", 6381)
161
- end
162
- end
163
-
164
- def test_bgrewriteaof
165
- redis_mock(:bgrewriteaof => lambda { "+BGREWRITEAOF" }) do |redis|
166
- assert_equal "BGREWRITEAOF", redis.bgrewriteaof
167
- end
168
- end
169
-
170
- def test_config_get
171
- assert r.config(:get, "*")["timeout"] != nil
172
-
173
- config = r.config(:get, "timeout")
174
- assert_equal ["timeout"], config.keys
175
- assert config.values.compact.size > 0
176
- end
177
-
178
- def test_config_set
179
- begin
180
- assert_equal "OK", r.config(:set, "timeout", 200)
181
- assert_equal "200", r.config(:get, "*")["timeout"]
182
-
183
- assert_equal "OK", r.config(:set, "timeout", 100)
184
- assert_equal "100", r.config(:get, "*")["timeout"]
185
- ensure
186
- r.config :set, "timeout", 300
187
- end
188
- end
189
- end
@@ -1 +0,0 @@
1
- redis.pid
@@ -1,46 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require "helper"
4
- require "lint/blocking_commands"
5
-
6
- class TestDistributedBlockingCommands < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::BlockingCommands
10
-
11
- def test_blpop_raises
12
- assert_raises(Redis::Distributed::CannotDistribute) do
13
- r.blpop(["foo", "bar"])
14
- end
15
- end
16
-
17
- def test_blpop_raises_with_old_prototype
18
- assert_raises(Redis::Distributed::CannotDistribute) do
19
- r.blpop("foo", "bar", 0)
20
- end
21
- end
22
-
23
- def test_brpop_raises
24
- assert_raises(Redis::Distributed::CannotDistribute) do
25
- r.brpop(["foo", "bar"])
26
- end
27
- end
28
-
29
- def test_brpop_raises_with_old_prototype
30
- assert_raises(Redis::Distributed::CannotDistribute) do
31
- r.brpop("foo", "bar", 0)
32
- end
33
- end
34
-
35
- def test_brpoplpush_raises
36
- assert_raises(Redis::Distributed::CannotDistribute) do
37
- r.brpoplpush("foo", "bar")
38
- end
39
- end
40
-
41
- def test_brpoplpush_raises_with_old_prototype
42
- assert_raises(Redis::Distributed::CannotDistribute) do
43
- r.brpoplpush("foo", "bar", 0)
44
- end
45
- end
46
- end
@@ -1,10 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require "helper"
4
- require "lint/hashes"
5
-
6
- class TestDistributedCommandsOnHashes < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::Hashes
10
- end
@@ -1,22 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require "helper"
4
- require "lint/lists"
5
-
6
- class TestDistributedCommandsOnLists < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::Lists
10
-
11
- def test_rpoplpush
12
- assert_raise Redis::Distributed::CannotDistribute do
13
- r.rpoplpush("foo", "bar")
14
- end
15
- end
16
-
17
- def test_brpoplpush
18
- assert_raise Redis::Distributed::CannotDistribute do
19
- r.brpoplpush("foo", "bar", :timeout => 1)
20
- end
21
- end
22
- end
@@ -1,83 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require "helper"
4
- require "lint/sets"
5
-
6
- class TestDistributedCommandsOnSets < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::Sets
10
-
11
- def test_smove
12
- assert_raise Redis::Distributed::CannotDistribute do
13
- r.sadd "foo", "s1"
14
- r.sadd "bar", "s2"
15
-
16
- r.smove("foo", "bar", "s1")
17
- end
18
- end
19
-
20
- def test_sinter
21
- assert_raise Redis::Distributed::CannotDistribute do
22
- r.sadd "foo", "s1"
23
- r.sadd "foo", "s2"
24
- r.sadd "bar", "s2"
25
-
26
- r.sinter("foo", "bar")
27
- end
28
- end
29
-
30
- def test_sinterstore
31
- assert_raise Redis::Distributed::CannotDistribute do
32
- r.sadd "foo", "s1"
33
- r.sadd "foo", "s2"
34
- r.sadd "bar", "s2"
35
-
36
- r.sinterstore("baz", "foo", "bar")
37
- end
38
- end
39
-
40
- def test_sunion
41
- assert_raise Redis::Distributed::CannotDistribute do
42
- r.sadd "foo", "s1"
43
- r.sadd "foo", "s2"
44
- r.sadd "bar", "s2"
45
- r.sadd "bar", "s3"
46
-
47
- r.sunion("foo", "bar")
48
- end
49
- end
50
-
51
- def test_sunionstore
52
- assert_raise Redis::Distributed::CannotDistribute do
53
- r.sadd "foo", "s1"
54
- r.sadd "foo", "s2"
55
- r.sadd "bar", "s2"
56
- r.sadd "bar", "s3"
57
-
58
- r.sunionstore("baz", "foo", "bar")
59
- end
60
- end
61
-
62
- def test_sdiff
63
- assert_raise Redis::Distributed::CannotDistribute do
64
- r.sadd "foo", "s1"
65
- r.sadd "foo", "s2"
66
- r.sadd "bar", "s2"
67
- r.sadd "bar", "s3"
68
-
69
- r.sdiff("foo", "bar")
70
- end
71
- end
72
-
73
- def test_sdiffstore
74
- assert_raise Redis::Distributed::CannotDistribute do
75
- r.sadd "foo", "s1"
76
- r.sadd "foo", "s2"
77
- r.sadd "bar", "s2"
78
- r.sadd "bar", "s3"
79
-
80
- r.sdiffstore("baz", "foo", "bar")
81
- end
82
- end
83
- end
@@ -1,18 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require "helper"
4
- require "lint/sorted_sets"
5
-
6
- class TestDistributedCommandsOnSortedSets < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::SortedSets
10
-
11
- def test_zcount
12
- r.zadd "foo", 1, "s1"
13
- r.zadd "foo", 2, "s2"
14
- r.zadd "foo", 3, "s3"
15
-
16
- assert_equal 2, r.zcount("foo", 2, 3)
17
- end
18
- end
@@ -1,48 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require "helper"
4
- require "lint/strings"
5
-
6
- class TestDistributedCommandsOnStrings < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::Strings
10
-
11
- def test_mget
12
- assert_raise Redis::Distributed::CannotDistribute do
13
- r.mget("foo", "bar")
14
- end
15
- end
16
-
17
- def test_mget_mapped
18
- assert_raise Redis::Distributed::CannotDistribute do
19
- r.mapped_mget("foo", "bar")
20
- end
21
- end
22
-
23
- def test_mset
24
- assert_raise Redis::Distributed::CannotDistribute do
25
- r.mset(:foo, "s1", :bar, "s2")
26
- end
27
- end
28
-
29
- def test_mset_mapped
30
- assert_raise Redis::Distributed::CannotDistribute do
31
- r.mapped_mset(:foo => "s1", :bar => "s2")
32
- end
33
- end
34
-
35
- def test_msetnx
36
- assert_raise Redis::Distributed::CannotDistribute do
37
- r.set("foo", "s1")
38
- r.msetnx(:foo, "s2", :bar, "s3")
39
- end
40
- end
41
-
42
- def test_msetnx_mapped
43
- assert_raise Redis::Distributed::CannotDistribute do
44
- r.set("foo", "s1")
45
- r.mapped_msetnx(:foo => "s2", :bar => "s3")
46
- end
47
- end
48
- end
@@ -1,87 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require "helper"
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
- end