redis 3.0.1 → 3.0.2
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.
- data/CHANGELOG.md +21 -0
- data/README.md +3 -3
- data/examples/pubsub.rb +18 -12
- data/lib/redis.rb +165 -164
- data/lib/redis/client.rb +46 -6
- data/lib/redis/connection/ruby.rb +44 -12
- data/lib/redis/connection/synchrony.rb +11 -6
- data/lib/redis/distributed.rb +7 -4
- data/lib/redis/pipeline.rb +9 -4
- data/lib/redis/subscribe.rb +2 -2
- data/lib/redis/version.rb +1 -1
- data/test/distributed_internals_test.rb +26 -0
- data/test/distributed_remote_server_control_commands_test.rb +1 -1
- data/test/internals_test.rb +18 -0
- data/test/lint/sorted_sets.rb +37 -0
- data/test/lint/value_types.rb +12 -12
- data/test/remote_server_control_commands_test.rb +1 -1
- data/test/synchrony_driver.rb +32 -1
- data/test/transactions_test.rb +21 -5
- data/test/url_param_test.rb +68 -0
- metadata +2 -2
data/test/synchrony_driver.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require 'em-synchrony'
|
4
|
+
require 'em-synchrony/connection_pool'
|
4
5
|
|
5
6
|
require 'redis'
|
6
7
|
require 'redis/connection/synchrony'
|
7
8
|
|
9
|
+
|
8
10
|
require File.expand_path("./helper", File.dirname(__FILE__))
|
9
11
|
|
12
|
+
PORT = 6381
|
13
|
+
OPTIONS = {:port => PORT, :db => 15}
|
14
|
+
|
10
15
|
#
|
11
16
|
# if running under Eventmachine + Synchrony (Ruby 1.9+), then
|
12
17
|
# we can simulate the blocking API while performing the network
|
@@ -14,7 +19,7 @@ require File.expand_path("./helper", File.dirname(__FILE__))
|
|
14
19
|
#
|
15
20
|
|
16
21
|
EM.synchrony do
|
17
|
-
r = Redis.new
|
22
|
+
r = Redis.new OPTIONS
|
18
23
|
r.flushdb
|
19
24
|
|
20
25
|
r.rpush "foo", "s1"
|
@@ -53,5 +58,31 @@ EM.synchrony do
|
|
53
58
|
assert_equal "OK", r.client.call(:quit)
|
54
59
|
assert_equal "PONG", r.ping
|
55
60
|
|
61
|
+
|
62
|
+
rpool = EM::Synchrony::ConnectionPool.new(size: 5) { Redis.new OPTIONS }
|
63
|
+
|
64
|
+
result = rpool.watch 'foo' do |rd|
|
65
|
+
assert_kind_of Redis, rd
|
66
|
+
|
67
|
+
rd.set "foo", "s1"
|
68
|
+
rd.multi do |multi|
|
69
|
+
multi.set "foo", "s2"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
assert_equal nil, result
|
74
|
+
assert_equal "s1", rpool.get("foo")
|
75
|
+
|
76
|
+
result = rpool.watch "foo" do |rd|
|
77
|
+
assert_kind_of Redis, rd
|
78
|
+
|
79
|
+
rd.multi do |multi|
|
80
|
+
multi.set "foo", "s3"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
assert_equal ["OK"], result
|
85
|
+
assert_equal "s3", rpool.get("foo")
|
86
|
+
|
56
87
|
EM.stop
|
57
88
|
end
|
data/test/transactions_test.rb
CHANGED
@@ -147,6 +147,16 @@ class TestTransactions < Test::Unit::TestCase
|
|
147
147
|
assert_equal "s1", r.get("foo")
|
148
148
|
end
|
149
149
|
|
150
|
+
def test_raise_command_error_when_exec_fails
|
151
|
+
redis_mock(:exec => lambda { |*_| "-ERROR" }) do |redis|
|
152
|
+
assert_raise(Redis::CommandError) do
|
153
|
+
redis.multi do |m|
|
154
|
+
m.set "foo", "s1"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
150
160
|
def test_watch_with_an_unmodified_key
|
151
161
|
r.watch "foo"
|
152
162
|
r.multi do |multi|
|
@@ -188,8 +198,11 @@ class TestTransactions < Test::Unit::TestCase
|
|
188
198
|
end
|
189
199
|
|
190
200
|
def test_watch_with_a_block_and_an_unmodified_key
|
191
|
-
result = r.watch "foo" do
|
192
|
-
|
201
|
+
result = r.watch "foo" do |rd|
|
202
|
+
|
203
|
+
assert_same r, rd
|
204
|
+
|
205
|
+
rd.multi do |multi|
|
193
206
|
multi.set "foo", "s1"
|
194
207
|
end
|
195
208
|
end
|
@@ -199,9 +212,12 @@ class TestTransactions < Test::Unit::TestCase
|
|
199
212
|
end
|
200
213
|
|
201
214
|
def test_watch_with_a_block_and_a_modified_key
|
202
|
-
result = r.watch "foo" do
|
203
|
-
|
204
|
-
r
|
215
|
+
result = r.watch "foo" do |rd|
|
216
|
+
|
217
|
+
assert_same r, rd
|
218
|
+
|
219
|
+
rd.set "foo", "s1"
|
220
|
+
rd.multi do |multi|
|
205
221
|
multi.set "foo", "s2"
|
206
222
|
end
|
207
223
|
end
|
data/test/url_param_test.rb
CHANGED
@@ -24,6 +24,39 @@ class TestUrlParam < Test::Unit::TestCase
|
|
24
24
|
assert_equal "secr3t", redis.client.password
|
25
25
|
end
|
26
26
|
|
27
|
+
def test_allows_to_pass_in_a_url_with_string_key
|
28
|
+
redis = Redis.new "url" => "redis://:secr3t@foo.com:999/2"
|
29
|
+
|
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
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_unescape_password_from_url
|
37
|
+
redis = Redis.new :url => "redis://:secr3t%3A@foo.com:999/2"
|
38
|
+
|
39
|
+
assert_equal "secr3t:", redis.client.password
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_unescape_password_from_url_with_string_key
|
43
|
+
redis = Redis.new "url" => "redis://:secr3t%3A@foo.com:999/2"
|
44
|
+
|
45
|
+
assert_equal "secr3t:", redis.client.password
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_does_not_unescape_password_when_explicitly_passed
|
49
|
+
redis = Redis.new :url => "redis://:secr3t%3A@foo.com:999/2", :password => "secr3t%3A"
|
50
|
+
|
51
|
+
assert_equal "secr3t%3A", redis.client.password
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_does_not_unescape_password_when_explicitly_passed_with_string_key
|
55
|
+
redis = Redis.new :url => "redis://:secr3t%3A@foo.com:999/2", "password" => "secr3t%3A"
|
56
|
+
|
57
|
+
assert_equal "secr3t%3A", redis.client.password
|
58
|
+
end
|
59
|
+
|
27
60
|
def test_override_url_if_path_option_is_passed
|
28
61
|
redis = Redis.new :url => "redis://:secr3t@foo.com/foo:999/2", :path => "/tmp/redis.sock"
|
29
62
|
|
@@ -32,6 +65,14 @@ class TestUrlParam < Test::Unit::TestCase
|
|
32
65
|
assert_equal nil, redis.client.port
|
33
66
|
end
|
34
67
|
|
68
|
+
def test_override_url_if_path_option_is_passed_with_string_key
|
69
|
+
redis = Redis.new :url => "redis://:secr3t@foo.com/foo:999/2", "path" => "/tmp/redis.sock"
|
70
|
+
|
71
|
+
assert_equal "/tmp/redis.sock", redis.client.path
|
72
|
+
assert_equal nil, redis.client.host
|
73
|
+
assert_equal nil, redis.client.port
|
74
|
+
end
|
75
|
+
|
35
76
|
def test_overrides_url_if_another_connection_option_is_passed
|
36
77
|
redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", :port => 1000
|
37
78
|
|
@@ -41,6 +82,33 @@ class TestUrlParam < Test::Unit::TestCase
|
|
41
82
|
assert_equal "secr3t", redis.client.password
|
42
83
|
end
|
43
84
|
|
85
|
+
def test_overrides_url_if_another_connection_option_is_passed_with_string_key
|
86
|
+
redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", "port" => 1000
|
87
|
+
|
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
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_does_not_overrides_url_if_a_nil_option_is_passed
|
95
|
+
redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", :port => nil
|
96
|
+
|
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
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_does_not_overrides_url_if_a_nil_option_is_passed_with_string_key
|
104
|
+
redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", "port" => nil
|
105
|
+
|
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
|
110
|
+
end
|
111
|
+
|
44
112
|
def test_does_not_modify_the_passed_options
|
45
113
|
options = { :url => "redis://:secr3t@foo.com:999/2" }
|
46
114
|
|
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.0.
|
4
|
+
version: 3.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -17,7 +17,7 @@ authors:
|
|
17
17
|
autorequire:
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
|
-
date: 2012-
|
20
|
+
date: 2012-10-05 00:00:00.000000000 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rake
|