redis 3.0.0.rc1 → 3.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +50 -0
- data/.travis/Gemfile +11 -0
- data/CHANGELOG.md +47 -19
- data/README.md +160 -149
- data/Rakefile +15 -50
- data/examples/pubsub.rb +1 -1
- data/examples/unicorn/config.ru +1 -1
- data/examples/unicorn/unicorn.rb +1 -1
- data/lib/redis.rb +790 -390
- data/lib/redis/client.rb +137 -49
- data/lib/redis/connection/hiredis.rb +26 -15
- data/lib/redis/connection/ruby.rb +170 -53
- data/lib/redis/connection/synchrony.rb +23 -35
- data/lib/redis/distributed.rb +92 -32
- data/lib/redis/errors.rb +4 -2
- data/lib/redis/pipeline.rb +17 -6
- data/lib/redis/version.rb +1 -1
- data/redis.gemspec +4 -6
- data/test/blocking_commands_test.rb +42 -0
- data/test/command_map_test.rb +18 -17
- data/test/commands_on_hashes_test.rb +13 -12
- data/test/commands_on_lists_test.rb +35 -45
- data/test/commands_on_sets_test.rb +55 -54
- data/test/commands_on_sorted_sets_test.rb +106 -105
- data/test/commands_on_strings_test.rb +64 -55
- data/test/commands_on_value_types_test.rb +66 -54
- data/test/connection_handling_test.rb +136 -151
- data/test/distributed_blocking_commands_test.rb +33 -40
- data/test/distributed_commands_on_hashes_test.rb +6 -7
- data/test/distributed_commands_on_lists_test.rb +13 -14
- data/test/distributed_commands_on_sets_test.rb +57 -58
- data/test/distributed_commands_on_sorted_sets_test.rb +11 -12
- data/test/distributed_commands_on_strings_test.rb +31 -32
- data/test/distributed_commands_on_value_types_test.rb +61 -46
- data/test/distributed_commands_requiring_clustering_test.rb +108 -108
- data/test/distributed_connection_handling_test.rb +14 -15
- data/test/distributed_internals_test.rb +7 -19
- data/test/distributed_key_tags_test.rb +36 -36
- data/test/distributed_persistence_control_commands_test.rb +17 -14
- data/test/distributed_publish_subscribe_test.rb +61 -69
- data/test/distributed_remote_server_control_commands_test.rb +39 -28
- data/test/distributed_sorting_test.rb +12 -13
- data/test/distributed_test.rb +40 -41
- data/test/distributed_transactions_test.rb +20 -21
- data/test/encoding_test.rb +12 -9
- data/test/error_replies_test.rb +42 -36
- data/test/helper.rb +118 -85
- data/test/helper_test.rb +20 -6
- data/test/internals_test.rb +167 -103
- data/test/lint/blocking_commands.rb +124 -0
- data/test/lint/hashes.rb +115 -93
- data/test/lint/lists.rb +86 -80
- data/test/lint/sets.rb +68 -62
- data/test/lint/sorted_sets.rb +200 -195
- data/test/lint/strings.rb +112 -94
- data/test/lint/value_types.rb +76 -55
- data/test/persistence_control_commands_test.rb +17 -12
- data/test/pipelining_commands_test.rb +135 -126
- data/test/publish_subscribe_test.rb +105 -110
- data/test/remote_server_control_commands_test.rb +74 -58
- data/test/sorting_test.rb +31 -29
- data/test/support/connection/hiredis.rb +1 -0
- data/test/support/connection/ruby.rb +1 -0
- data/test/support/connection/synchrony.rb +17 -0
- data/test/{redis_mock.rb → support/redis_mock.rb} +24 -21
- data/test/support/wire/synchrony.rb +24 -0
- data/test/support/wire/thread.rb +5 -0
- data/test/synchrony_driver.rb +9 -9
- data/test/test.conf +1 -1
- data/test/thread_safety_test.rb +21 -19
- data/test/transactions_test.rb +189 -118
- data/test/unknown_commands_test.rb +9 -8
- data/test/url_param_test.rb +46 -41
- metadata +28 -43
- data/TODO.md +0 -4
- data/benchmarking/thread_safety.rb +0 -38
- data/test/lint/internals.rb +0 -36
data/test/lint/strings.rb
CHANGED
@@ -1,133 +1,151 @@
|
|
1
|
-
|
1
|
+
module Lint
|
2
2
|
|
3
|
-
|
3
|
+
module Strings
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
def test_set_and_get
|
6
|
+
r.set("foo", "s1")
|
7
7
|
|
8
|
-
|
9
|
-
end
|
8
|
+
assert_equal "s1", r.get("foo")
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
def test_set_and_get_with_brackets
|
12
|
+
r["foo"] = "s1"
|
13
13
|
|
14
|
-
|
15
|
-
end
|
14
|
+
assert_equal "s1", r["foo"]
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
def test_set_and_get_with_brackets_and_symbol
|
18
|
+
r[:foo] = "s1"
|
19
19
|
|
20
|
-
|
21
|
-
end
|
20
|
+
assert_equal "s1", r[:foo]
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
def test_set_and_get_with_newline_characters
|
24
|
+
r.set("foo", "1\n")
|
25
25
|
|
26
|
-
|
27
|
-
end
|
26
|
+
assert_equal "1\n", r.get("foo")
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
def test_set_and_get_with_ascii_characters
|
30
|
+
if defined?(Encoding)
|
31
|
+
with_external_encoding("ASCII-8BIT") do
|
32
|
+
(0..255).each do |i|
|
33
|
+
str = "#{i.chr}---#{i.chr}"
|
34
|
+
r.set("foo", str)
|
35
|
+
|
36
|
+
assert_equal str, r.get("foo")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
34
41
|
|
35
|
-
|
42
|
+
def test_setex
|
43
|
+
assert r.setex("foo", 1, "bar")
|
44
|
+
assert_equal "bar", r.get("foo")
|
45
|
+
assert [0, 1].include? r.ttl("foo")
|
36
46
|
end
|
37
|
-
end
|
38
|
-
end if defined?(Encoding)
|
39
47
|
|
40
|
-
|
41
|
-
|
42
|
-
r = Redis.new(OPTIONS.merge(:port => 6380))
|
48
|
+
def test_psetex
|
49
|
+
return if version < "2.5.4"
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
|
51
|
+
assert r.psetex("foo", 1000, "bar")
|
52
|
+
assert_equal "bar", r.get("foo")
|
53
|
+
assert [0, 1].include? r.ttl("foo")
|
54
|
+
end
|
47
55
|
|
48
|
-
|
49
|
-
|
56
|
+
def test_getset
|
57
|
+
r.set("foo", "bar")
|
50
58
|
|
51
|
-
|
52
|
-
|
53
|
-
end
|
59
|
+
assert_equal "bar", r.getset("foo", "baz")
|
60
|
+
assert_equal "baz", r.get("foo")
|
61
|
+
end
|
54
62
|
|
55
|
-
|
56
|
-
|
63
|
+
def test_setnx
|
64
|
+
r.set("foo", "s1")
|
57
65
|
|
58
|
-
|
66
|
+
assert_equal "s1", r.get("foo")
|
59
67
|
|
60
|
-
|
68
|
+
r.setnx("foo", "s2")
|
61
69
|
|
62
|
-
|
63
|
-
end
|
70
|
+
assert_equal "s1", r.get("foo")
|
71
|
+
end
|
64
72
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
73
|
+
def test_incr
|
74
|
+
assert_equal 1, r.incr("foo")
|
75
|
+
assert_equal 2, r.incr("foo")
|
76
|
+
assert_equal 3, r.incr("foo")
|
77
|
+
end
|
70
78
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
79
|
+
def test_incrby
|
80
|
+
assert_equal 1, r.incrby("foo", 1)
|
81
|
+
assert_equal 3, r.incrby("foo", 2)
|
82
|
+
assert_equal 6, r.incrby("foo", 3)
|
83
|
+
end
|
76
84
|
|
77
|
-
|
78
|
-
|
85
|
+
def test_incrbyfloat
|
86
|
+
return if version < "2.5.4"
|
79
87
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
88
|
+
assert_equal 1.23, r.incrbyfloat("foo", 1.23)
|
89
|
+
assert_equal 2 , r.incrbyfloat("foo", 0.77)
|
90
|
+
assert_equal 1.9 , r.incrbyfloat("foo", -0.1)
|
91
|
+
end
|
84
92
|
|
85
|
-
|
86
|
-
|
93
|
+
def test_decr
|
94
|
+
r.set("foo", 3)
|
87
95
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
96
|
+
assert_equal 2, r.decr("foo")
|
97
|
+
assert_equal 1, r.decr("foo")
|
98
|
+
assert_equal 0, r.decr("foo")
|
99
|
+
end
|
92
100
|
|
93
|
-
|
94
|
-
|
95
|
-
r.append "foo", "1"
|
101
|
+
def test_decrby
|
102
|
+
r.set("foo", 6)
|
96
103
|
|
97
|
-
|
98
|
-
|
104
|
+
assert_equal 3, r.decrby("foo", 3)
|
105
|
+
assert_equal 1, r.decrby("foo", 2)
|
106
|
+
assert_equal 0, r.decrby("foo", 1)
|
107
|
+
end
|
99
108
|
|
100
|
-
|
101
|
-
|
109
|
+
def test_append
|
110
|
+
r.set "foo", "s"
|
111
|
+
r.append "foo", "1"
|
102
112
|
|
103
|
-
|
104
|
-
|
105
|
-
assert_equal 0, r.getbit("foo", 3)
|
106
|
-
assert_equal 0, r.getbit("foo", 4)
|
107
|
-
assert_equal 0, r.getbit("foo", 5)
|
108
|
-
assert_equal 0, r.getbit("foo", 6)
|
109
|
-
assert_equal 1, r.getbit("foo", 7)
|
110
|
-
end
|
113
|
+
assert_equal "s1", r.get("foo")
|
114
|
+
end
|
111
115
|
|
112
|
-
|
113
|
-
|
116
|
+
def test_getbit
|
117
|
+
r.set("foo", "a")
|
114
118
|
|
115
|
-
|
119
|
+
assert_equal 1, r.getbit("foo", 1)
|
120
|
+
assert_equal 1, r.getbit("foo", 2)
|
121
|
+
assert_equal 0, r.getbit("foo", 3)
|
122
|
+
assert_equal 0, r.getbit("foo", 4)
|
123
|
+
assert_equal 0, r.getbit("foo", 5)
|
124
|
+
assert_equal 0, r.getbit("foo", 6)
|
125
|
+
assert_equal 1, r.getbit("foo", 7)
|
126
|
+
end
|
116
127
|
|
117
|
-
|
118
|
-
|
128
|
+
def test_setbit
|
129
|
+
r.set("foo", "a")
|
119
130
|
|
120
|
-
|
121
|
-
r.set("foo", "abcde")
|
131
|
+
r.setbit("foo", 6, 1)
|
122
132
|
|
123
|
-
|
124
|
-
|
125
|
-
end
|
133
|
+
assert_equal "c", r.get("foo")
|
134
|
+
end
|
126
135
|
|
127
|
-
|
128
|
-
|
136
|
+
def test_getrange
|
137
|
+
r.set("foo", "abcde")
|
129
138
|
|
130
|
-
|
139
|
+
assert_equal "bcd", r.getrange("foo", 1, 3)
|
140
|
+
assert_equal "abcde", r.getrange("foo", 0, -1)
|
141
|
+
end
|
131
142
|
|
132
|
-
|
143
|
+
def test_setrange
|
144
|
+
r.set("foo", "abcde")
|
145
|
+
|
146
|
+
r.setrange("foo", 1, "bar")
|
147
|
+
|
148
|
+
assert_equal "abare", r.get("foo")
|
149
|
+
end
|
150
|
+
end
|
133
151
|
end
|
data/test/lint/value_types.rb
CHANGED
@@ -1,81 +1,102 @@
|
|
1
|
-
|
1
|
+
module Lint
|
2
2
|
|
3
|
-
|
3
|
+
module ValueTypes
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
def test_exists
|
6
|
+
assert_equal false, r.exists("foo")
|
7
7
|
|
8
|
-
|
8
|
+
r.set("foo", "s1")
|
9
9
|
|
10
|
-
|
11
|
-
end
|
10
|
+
assert_equal true, r.exists("foo")
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
def test_type
|
14
|
+
assert_equal "none", r.type("foo")
|
15
15
|
|
16
|
-
|
16
|
+
r.set("foo", "s1")
|
17
17
|
|
18
|
-
|
19
|
-
end
|
18
|
+
assert_equal "string", r.type("foo")
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def test_keys
|
22
|
+
r.set("f", "s1")
|
23
|
+
r.set("fo", "s2")
|
24
|
+
r.set("foo", "s3")
|
25
25
|
|
26
|
-
|
27
|
-
end
|
26
|
+
assert_equal ["f","fo", "foo"], r.keys("f*").sort
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def test_expire
|
30
|
+
r.set("foo", "s1")
|
31
|
+
assert r.expire("foo", 1)
|
32
|
+
assert [0, 1].include? r.ttl("foo")
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
35
|
+
def test_pexpire
|
36
|
+
return if version < "2.5.4"
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
r.set("foo", "s1")
|
39
|
+
assert r.pexpire("foo", 1000)
|
40
|
+
assert [0, 1].include? r.ttl("foo")
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
def test_expireat
|
44
|
+
r.set("foo", "s1")
|
45
|
+
assert r.expireat("foo", (Time.now + 1).to_i)
|
46
|
+
assert [0, 1].include? r.ttl("foo")
|
47
|
+
end
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
r.expire("foo", 1)
|
48
|
-
r.persist("foo")
|
49
|
+
def test_pexpireat
|
50
|
+
return if version < "2.5.4"
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
+
r.set("foo", "s1")
|
53
|
+
assert r.pexpireat("foo", (Time.now + 1).to_i * 1_000)
|
54
|
+
assert [0, 1].include? r.ttl("foo")
|
55
|
+
end
|
52
56
|
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
def test_persist
|
58
|
+
r.set("foo", "s1")
|
59
|
+
r.expire("foo", 1)
|
60
|
+
r.persist("foo")
|
56
61
|
|
57
|
-
|
58
|
-
end
|
62
|
+
assert(-1 == r.ttl("foo"))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_ttl
|
66
|
+
r.set("foo", "s1")
|
67
|
+
r.expire("foo", 1)
|
68
|
+
assert [0, 1].include? r.ttl("foo")
|
69
|
+
end
|
59
70
|
|
60
|
-
|
61
|
-
|
62
|
-
r.flushdb
|
71
|
+
def test_pttl
|
72
|
+
return if version < "2.5.4"
|
63
73
|
|
64
|
-
|
74
|
+
r.set("foo", "s1")
|
75
|
+
r.expire("foo", 1)
|
76
|
+
assert 1000 >= r.pttl("foo")
|
77
|
+
end
|
65
78
|
|
66
|
-
|
79
|
+
def test_move
|
80
|
+
r.select 14
|
81
|
+
r.flushdb
|
67
82
|
|
68
|
-
|
69
|
-
r.set "bar", "s2"
|
83
|
+
r.set "bar", "s3"
|
70
84
|
|
71
|
-
|
72
|
-
assert nil == r.get("foo")
|
85
|
+
r.select 15
|
73
86
|
|
74
|
-
|
75
|
-
|
87
|
+
r.set "foo", "s1"
|
88
|
+
r.set "bar", "s2"
|
76
89
|
|
77
|
-
|
90
|
+
assert r.move("foo", 14)
|
91
|
+
assert_equal nil, r.get("foo")
|
78
92
|
|
79
|
-
|
80
|
-
|
93
|
+
assert !r.move("bar", 14)
|
94
|
+
assert_equal "s2", r.get("bar")
|
95
|
+
|
96
|
+
r.select 14
|
97
|
+
|
98
|
+
assert_equal "s1", r.get("foo")
|
99
|
+
assert_equal "s3", r.get("bar")
|
100
|
+
end
|
101
|
+
end
|
81
102
|
end
|
@@ -1,21 +1,26 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require "helper"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class TestPersistenceControlCommands < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Helper::Client
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def test_save
|
10
|
+
redis_mock(:save => lambda { "+SAVE" }) do |redis|
|
11
|
+
assert_equal "SAVE", redis.save
|
12
|
+
end
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def test_bgsave
|
16
|
+
redis_mock(:bgsave => lambda { "+BGSAVE" }) do |redis|
|
17
|
+
assert_equal "BGSAVE", redis.bgsave
|
18
|
+
end
|
16
19
|
end
|
17
|
-
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
def test_lastsave
|
22
|
+
redis_mock(:lastsave => lambda { "+LASTSAVE" }) do |redis|
|
23
|
+
assert_equal "LASTSAVE", redis.lastsave
|
24
|
+
end
|
25
|
+
end
|
21
26
|
end
|
@@ -1,186 +1,195 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require "helper"
|
4
4
|
|
5
|
-
|
6
|
-
init Redis.new(OPTIONS)
|
7
|
-
end
|
5
|
+
class TestPipeliningCommands < Test::Unit::TestCase
|
8
6
|
|
9
|
-
|
10
|
-
r.pipelined do
|
11
|
-
r.lpush "foo", "s1"
|
12
|
-
r.lpush "foo", "s2"
|
13
|
-
end
|
7
|
+
include Helper::Client
|
14
8
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
def test_bulk_commands
|
10
|
+
r.pipelined do
|
11
|
+
r.lpush "foo", "s1"
|
12
|
+
r.lpush "foo", "s2"
|
13
|
+
end
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
r.mset("baz", "s3", "qux", "s4")
|
15
|
+
assert_equal 2, r.llen("foo")
|
16
|
+
assert_equal "s2", r.lpop("foo")
|
17
|
+
assert_equal "s1", r.lpop("foo")
|
24
18
|
end
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
20
|
+
def test_multi_bulk_commands
|
21
|
+
r.pipelined do
|
22
|
+
r.mset("foo", "s1", "bar", "s2")
|
23
|
+
r.mset("baz", "s3", "qux", "s4")
|
24
|
+
end
|
31
25
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
r.mset("baz", "s3", "qux", "s4")
|
26
|
+
assert_equal "s1", r.get("foo")
|
27
|
+
assert_equal "s2", r.get("bar")
|
28
|
+
assert_equal "s3", r.get("baz")
|
29
|
+
assert_equal "s4", r.get("qux")
|
37
30
|
end
|
38
31
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
32
|
+
def test_bulk_and_multi_bulk_commands_mixed
|
33
|
+
r.pipelined do
|
34
|
+
r.lpush "foo", "s1"
|
35
|
+
r.lpush "foo", "s2"
|
36
|
+
r.mset("baz", "s3", "qux", "s4")
|
37
|
+
end
|
45
38
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
39
|
+
assert_equal 2, r.llen("foo")
|
40
|
+
assert_equal "s2", r.lpop("foo")
|
41
|
+
assert_equal "s1", r.lpop("foo")
|
42
|
+
assert_equal "s3", r.get("baz")
|
43
|
+
assert_equal "s4", r.get("qux")
|
51
44
|
end
|
52
45
|
|
53
|
-
|
54
|
-
assert "s2" == r.lpop("foo")
|
55
|
-
assert "s1" == r.lpop("foo")
|
56
|
-
assert "s3" == r.get("baz")
|
57
|
-
assert "s4" == r.get("qux")
|
58
|
-
end
|
59
|
-
|
60
|
-
test "Pipelined with an empty block" do |r|
|
61
|
-
assert_nothing_raised do
|
46
|
+
def test_multi_bulk_and_bulk_commands_mixed
|
62
47
|
r.pipelined do
|
48
|
+
r.mset("baz", "s3", "qux", "s4")
|
49
|
+
r.lpush "foo", "s1"
|
50
|
+
r.lpush "foo", "s2"
|
63
51
|
end
|
52
|
+
|
53
|
+
assert_equal 2, r.llen("foo")
|
54
|
+
assert_equal "s2", r.lpop("foo")
|
55
|
+
assert_equal "s1", r.lpop("foo")
|
56
|
+
assert_equal "s3", r.get("baz")
|
57
|
+
assert_equal "s4", r.get("qux")
|
64
58
|
end
|
65
59
|
|
66
|
-
|
67
|
-
|
60
|
+
def test_pipelined_with_an_empty_block
|
61
|
+
assert_nothing_raised do
|
62
|
+
r.pipelined do
|
63
|
+
end
|
64
|
+
end
|
68
65
|
|
69
|
-
|
70
|
-
result = r.pipelined do
|
71
|
-
r.set "foo", "bar"
|
72
|
-
r.get "foo"
|
73
|
-
r.get "bar"
|
66
|
+
assert_equal 0, r.dbsize
|
74
67
|
end
|
75
68
|
|
76
|
-
|
77
|
-
|
69
|
+
def test_returning_the_result_of_a_pipeline
|
70
|
+
result = r.pipelined do
|
71
|
+
r.set "foo", "bar"
|
72
|
+
r.get "foo"
|
73
|
+
r.get "bar"
|
74
|
+
end
|
78
75
|
|
79
|
-
|
80
|
-
r.pipelined do
|
81
|
-
@first = r.sadd("foo", 1)
|
82
|
-
@second = r.sadd("foo", 1)
|
76
|
+
assert_equal ["OK", "bar", nil], result
|
83
77
|
end
|
84
78
|
|
85
|
-
|
86
|
-
assert_equal false, @second.value
|
87
|
-
end
|
88
|
-
|
89
|
-
# Although we could support accessing the values in these futures,
|
90
|
-
# it doesn't make a lot of sense.
|
91
|
-
test "Assignment of results inside the block with errors" do |r|
|
92
|
-
assert_raise do
|
79
|
+
def test_assignment_of_results_inside_the_block
|
93
80
|
r.pipelined do
|
94
|
-
r.doesnt_exist
|
95
81
|
@first = r.sadd("foo", 1)
|
96
|
-
r.doesnt_exist
|
97
82
|
@second = r.sadd("foo", 1)
|
98
|
-
r.doesnt_exist
|
99
83
|
end
|
100
|
-
end
|
101
84
|
|
102
|
-
|
103
|
-
|
104
|
-
end
|
85
|
+
assert_equal true, @first.value
|
86
|
+
assert_equal false, @second.value
|
87
|
+
end
|
88
|
+
|
89
|
+
# Although we could support accessing the values in these futures,
|
90
|
+
# it doesn't make a lot of sense.
|
91
|
+
def test_assignment_of_results_inside_the_block_with_errors
|
92
|
+
assert_raise(Redis::CommandError) do
|
93
|
+
r.pipelined do
|
94
|
+
r.doesnt_exist
|
95
|
+
@first = r.sadd("foo", 1)
|
96
|
+
r.doesnt_exist
|
97
|
+
@second = r.sadd("foo", 1)
|
98
|
+
r.doesnt_exist
|
99
|
+
end
|
100
|
+
end
|
105
101
|
|
106
|
-
|
107
|
-
|
108
|
-
|
102
|
+
assert_raise(Redis::FutureNotReady) { @first.value }
|
103
|
+
assert_raise(Redis::FutureNotReady) { @second.value }
|
104
|
+
end
|
109
105
|
|
106
|
+
def test_assignment_of_results_inside_a_nested_block
|
110
107
|
r.pipelined do
|
111
|
-
@
|
108
|
+
@first = r.sadd("foo", 1)
|
109
|
+
|
110
|
+
r.pipelined do
|
111
|
+
@second = r.sadd("foo", 1)
|
112
|
+
end
|
112
113
|
end
|
114
|
+
|
115
|
+
assert_equal true, @first.value
|
116
|
+
assert_equal false, @second.value
|
113
117
|
end
|
114
118
|
|
115
|
-
|
116
|
-
|
117
|
-
|
119
|
+
def test_futures_raise_when_confused_with_something_else
|
120
|
+
r.pipelined do
|
121
|
+
@result = r.sadd("foo", 1)
|
122
|
+
end
|
118
123
|
|
119
|
-
|
120
|
-
r.pipelined do
|
121
|
-
@result = r.sadd("foo", 1)
|
124
|
+
assert_raise(NoMethodError) { @result.to_s }
|
122
125
|
end
|
123
126
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
assert_raise(Redis::FutureNotReady) do
|
130
|
-
r.sadd("foo", 1).value
|
127
|
+
def test_futures_raise_when_trying_to_access_their_values_too_early
|
128
|
+
r.pipelined do
|
129
|
+
assert_raise(Redis::FutureNotReady) do
|
130
|
+
r.sadd("foo", 1).value
|
131
|
+
end
|
131
132
|
end
|
132
133
|
end
|
133
|
-
end
|
134
134
|
|
135
|
-
|
136
|
-
|
137
|
-
|
135
|
+
def test_returning_the_result_of_an_empty_pipeline
|
136
|
+
result = r.pipelined do
|
137
|
+
end
|
138
138
|
|
139
|
-
|
140
|
-
end
|
139
|
+
assert_equal [], result
|
140
|
+
end
|
141
141
|
|
142
|
-
|
143
|
-
r.pipelined do
|
144
|
-
r.set("foo", "s1")
|
142
|
+
def test_nesting_pipeline_blocks
|
145
143
|
r.pipelined do
|
146
|
-
r.set("
|
144
|
+
r.set("foo", "s1")
|
145
|
+
r.pipelined do
|
146
|
+
r.set("bar", "s2")
|
147
|
+
end
|
147
148
|
end
|
149
|
+
|
150
|
+
assert_equal "s1", r.get("foo")
|
151
|
+
assert_equal "s2", r.get("bar")
|
148
152
|
end
|
149
153
|
|
150
|
-
|
151
|
-
|
152
|
-
|
154
|
+
def test_info_in_a_pipeline_returns_hash
|
155
|
+
result = r.pipelined do
|
156
|
+
r.info
|
157
|
+
end
|
153
158
|
|
154
|
-
|
155
|
-
result = r.pipelined do
|
156
|
-
r.info
|
159
|
+
assert result.first.kind_of?(Hash)
|
157
160
|
end
|
158
161
|
|
159
|
-
|
160
|
-
|
162
|
+
def test_config_get_in_a_pipeline_returns_hash
|
163
|
+
result = r.pipelined do
|
164
|
+
r.config(:get, "*")
|
165
|
+
end
|
161
166
|
|
162
|
-
|
163
|
-
result = r.pipelined do
|
164
|
-
r.config(:get, "*")
|
167
|
+
assert result.first.kind_of?(Hash)
|
165
168
|
end
|
166
169
|
|
167
|
-
|
168
|
-
|
170
|
+
def test_hgetall_in_a_pipeline_returns_hash
|
171
|
+
r.hmset("hash", "field", "value")
|
172
|
+
result = r.pipelined do
|
173
|
+
r.hgetall("hash")
|
174
|
+
end
|
169
175
|
|
170
|
-
|
171
|
-
r.hmset("hash", "field", "value")
|
172
|
-
result = r.pipelined do
|
173
|
-
r.hgetall("hash")
|
176
|
+
assert_equal result.first, { "field" => "value" }
|
174
177
|
end
|
175
178
|
|
176
|
-
|
177
|
-
|
179
|
+
def test_keys_in_a_pipeline
|
180
|
+
r.set("key", "value")
|
181
|
+
result = r.pipelined do
|
182
|
+
r.keys("*")
|
183
|
+
end
|
178
184
|
|
179
|
-
|
180
|
-
r.set("key", "value")
|
181
|
-
result = r.pipelined do
|
182
|
-
r.keys("*")
|
185
|
+
assert_equal ["key"], result.first
|
183
186
|
end
|
184
187
|
|
185
|
-
|
188
|
+
def test_pipeline_yields_a_connection
|
189
|
+
r.pipelined do |p|
|
190
|
+
p.set("foo", "bar")
|
191
|
+
end
|
192
|
+
|
193
|
+
assert_equal "bar", r.get("foo")
|
194
|
+
end
|
186
195
|
end
|