redis 4.0.1 → 4.8.1
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +220 -0
- data/README.md +152 -28
- data/lib/redis/client.rb +171 -107
- data/lib/redis/cluster/command.rb +79 -0
- data/lib/redis/cluster/command_loader.rb +33 -0
- data/lib/redis/cluster/key_slot_converter.rb +72 -0
- data/lib/redis/cluster/node.rb +120 -0
- data/lib/redis/cluster/node_key.rb +31 -0
- data/lib/redis/cluster/node_loader.rb +34 -0
- data/lib/redis/cluster/option.rb +100 -0
- data/lib/redis/cluster/slot.rb +86 -0
- data/lib/redis/cluster/slot_loader.rb +46 -0
- data/lib/redis/cluster.rb +315 -0
- data/lib/redis/commands/bitmaps.rb +63 -0
- data/lib/redis/commands/cluster.rb +45 -0
- data/lib/redis/commands/connection.rb +58 -0
- data/lib/redis/commands/geo.rb +84 -0
- data/lib/redis/commands/hashes.rb +251 -0
- data/lib/redis/commands/hyper_log_log.rb +37 -0
- data/lib/redis/commands/keys.rb +455 -0
- data/lib/redis/commands/lists.rb +290 -0
- data/lib/redis/commands/pubsub.rb +72 -0
- data/lib/redis/commands/scripting.rb +114 -0
- data/lib/redis/commands/server.rb +188 -0
- data/lib/redis/commands/sets.rb +223 -0
- data/lib/redis/commands/sorted_sets.rb +812 -0
- data/lib/redis/commands/streams.rb +382 -0
- data/lib/redis/commands/strings.rb +313 -0
- data/lib/redis/commands/transactions.rb +139 -0
- data/lib/redis/commands.rb +240 -0
- data/lib/redis/connection/command_helper.rb +5 -2
- data/lib/redis/connection/hiredis.rb +7 -5
- data/lib/redis/connection/registry.rb +2 -1
- data/lib/redis/connection/ruby.rb +139 -111
- data/lib/redis/connection/synchrony.rb +17 -10
- data/lib/redis/connection.rb +3 -1
- data/lib/redis/distributed.rb +244 -87
- data/lib/redis/errors.rb +57 -0
- data/lib/redis/hash_ring.rb +15 -14
- data/lib/redis/pipeline.rb +181 -10
- data/lib/redis/subscribe.rb +11 -12
- data/lib/redis/version.rb +3 -1
- data/lib/redis.rb +180 -2716
- metadata +45 -195
- data/.gitignore +0 -16
- data/.travis/Gemfile +0 -13
- data/.travis.yml +0 -73
- data/.yardopts +0 -3
- data/Gemfile +0 -3
- data/benchmarking/logging.rb +0 -71
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/bors.toml +0 -14
- data/examples/basic.rb +0 -15
- data/examples/consistency.rb +0 -114
- data/examples/dist_redis.rb +0 -43
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -37
- data/examples/sentinel/sentinel.conf +0 -9
- data/examples/sentinel/start +0 -49
- data/examples/sentinel.rb +0 -41
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/makefile +0 -42
- data/redis.gemspec +0 -42
- data/test/bitpos_test.rb +0 -63
- data/test/blocking_commands_test.rb +0 -40
- data/test/client_test.rb +0 -59
- data/test/command_map_test.rb +0 -28
- data/test/commands_on_hashes_test.rb +0 -19
- data/test/commands_on_hyper_log_log_test.rb +0 -19
- data/test/commands_on_lists_test.rb +0 -18
- data/test/commands_on_sets_test.rb +0 -75
- data/test/commands_on_sorted_sets_test.rb +0 -150
- data/test/commands_on_strings_test.rb +0 -99
- data/test/commands_on_value_types_test.rb +0 -171
- data/test/connection_handling_test.rb +0 -275
- data/test/connection_test.rb +0 -57
- data/test/db/.gitkeep +0 -0
- data/test/distributed_blocking_commands_test.rb +0 -44
- data/test/distributed_commands_on_hashes_test.rb +0 -8
- data/test/distributed_commands_on_hyper_log_log_test.rb +0 -31
- data/test/distributed_commands_on_lists_test.rb +0 -20
- data/test/distributed_commands_on_sets_test.rb +0 -106
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -16
- data/test/distributed_commands_on_strings_test.rb +0 -69
- data/test/distributed_commands_on_value_types_test.rb +0 -93
- data/test/distributed_commands_requiring_clustering_test.rb +0 -162
- data/test/distributed_connection_handling_test.rb +0 -21
- data/test/distributed_internals_test.rb +0 -68
- data/test/distributed_key_tags_test.rb +0 -50
- data/test/distributed_persistence_control_commands_test.rb +0 -24
- data/test/distributed_publish_subscribe_test.rb +0 -90
- data/test/distributed_remote_server_control_commands_test.rb +0 -64
- data/test/distributed_scripting_test.rb +0 -100
- data/test/distributed_sorting_test.rb +0 -18
- data/test/distributed_test.rb +0 -56
- data/test/distributed_transactions_test.rb +0 -30
- data/test/encoding_test.rb +0 -14
- data/test/error_replies_test.rb +0 -57
- data/test/fork_safety_test.rb +0 -60
- data/test/helper.rb +0 -201
- data/test/helper_test.rb +0 -22
- data/test/internals_test.rb +0 -389
- data/test/lint/blocking_commands.rb +0 -150
- data/test/lint/hashes.rb +0 -162
- data/test/lint/hyper_log_log.rb +0 -60
- data/test/lint/lists.rb +0 -143
- data/test/lint/sets.rb +0 -140
- data/test/lint/sorted_sets.rb +0 -316
- data/test/lint/strings.rb +0 -246
- data/test/lint/value_types.rb +0 -130
- data/test/persistence_control_commands_test.rb +0 -24
- data/test/pipelining_commands_test.rb +0 -238
- data/test/publish_subscribe_test.rb +0 -280
- data/test/remote_server_control_commands_test.rb +0 -175
- data/test/scanning_test.rb +0 -407
- data/test/scripting_test.rb +0 -76
- data/test/sentinel_command_test.rb +0 -78
- data/test/sentinel_test.rb +0 -253
- data/test/sorting_test.rb +0 -57
- data/test/ssl_test.rb +0 -69
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -130
- data/test/support/ssl/gen_certs.sh +0 -31
- data/test/support/ssl/trusted-ca.crt +0 -25
- data/test/support/ssl/trusted-ca.key +0 -27
- data/test/support/ssl/trusted-cert.crt +0 -81
- data/test/support/ssl/trusted-cert.key +0 -28
- data/test/support/ssl/untrusted-ca.crt +0 -26
- data/test/support/ssl/untrusted-ca.key +0 -27
- data/test/support/ssl/untrusted-cert.crt +0 -82
- data/test/support/ssl/untrusted-cert.key +0 -28
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -85
- data/test/test.conf.erb +0 -9
- data/test/thread_safety_test.rb +0 -60
- data/test/transactions_test.rb +0 -262
- data/test/unknown_commands_test.rb +0 -12
- data/test/url_param_test.rb +0 -136
data/test/lint/strings.rb
DELETED
@@ -1,246 +0,0 @@
|
|
1
|
-
module Lint
|
2
|
-
|
3
|
-
module Strings
|
4
|
-
|
5
|
-
def test_set_and_get
|
6
|
-
r.set("foo", "s1")
|
7
|
-
|
8
|
-
assert_equal "s1", r.get("foo")
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_set_and_get_with_newline_characters
|
12
|
-
r.set("foo", "1\n")
|
13
|
-
|
14
|
-
assert_equal "1\n", r.get("foo")
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_set_and_get_with_non_string_value
|
18
|
-
value = ["a", "b"]
|
19
|
-
|
20
|
-
r.set("foo", value)
|
21
|
-
|
22
|
-
assert_equal value.to_s, r.get("foo")
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_set_and_get_with_ascii_characters
|
26
|
-
with_external_encoding("ASCII-8BIT") do
|
27
|
-
(0..255).each do |i|
|
28
|
-
str = "#{i.chr}---#{i.chr}"
|
29
|
-
r.set("foo", str)
|
30
|
-
|
31
|
-
assert_equal str, r.get("foo")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_set_with_ex
|
37
|
-
target_version "2.6.12" do
|
38
|
-
r.set("foo", "bar", :ex => 2)
|
39
|
-
assert_in_range 0..2, r.ttl("foo")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_set_with_px
|
44
|
-
target_version "2.6.12" do
|
45
|
-
r.set("foo", "bar", :px => 2000)
|
46
|
-
assert_in_range 0..2, r.ttl("foo")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_set_with_nx
|
51
|
-
target_version "2.6.12" do
|
52
|
-
r.set("foo", "qux", :nx => true)
|
53
|
-
assert !r.set("foo", "bar", :nx => true)
|
54
|
-
assert_equal "qux", r.get("foo")
|
55
|
-
|
56
|
-
r.del("foo")
|
57
|
-
assert r.set("foo", "bar", :nx => true)
|
58
|
-
assert_equal "bar", r.get("foo")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_set_with_xx
|
63
|
-
target_version "2.6.12" do
|
64
|
-
r.set("foo", "qux")
|
65
|
-
assert r.set("foo", "bar", :xx => true)
|
66
|
-
assert_equal "bar", r.get("foo")
|
67
|
-
|
68
|
-
r.del("foo")
|
69
|
-
assert !r.set("foo", "bar", :xx => true)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_setex
|
74
|
-
assert r.setex("foo", 1, "bar")
|
75
|
-
assert_equal "bar", r.get("foo")
|
76
|
-
assert [0, 1].include? r.ttl("foo")
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_setex_with_non_string_value
|
80
|
-
value = ["b", "a", "r"]
|
81
|
-
|
82
|
-
assert r.setex("foo", 1, value)
|
83
|
-
assert_equal value.to_s, r.get("foo")
|
84
|
-
assert [0, 1].include? r.ttl("foo")
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_psetex
|
88
|
-
target_version "2.5.4" do
|
89
|
-
assert r.psetex("foo", 1000, "bar")
|
90
|
-
assert_equal "bar", r.get("foo")
|
91
|
-
assert [0, 1].include? r.ttl("foo")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_psetex_with_non_string_value
|
96
|
-
target_version "2.5.4" do
|
97
|
-
value = ["b", "a", "r"]
|
98
|
-
|
99
|
-
assert r.psetex("foo", 1000, value)
|
100
|
-
assert_equal value.to_s, r.get("foo")
|
101
|
-
assert [0, 1].include? r.ttl("foo")
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_getset
|
106
|
-
r.set("foo", "bar")
|
107
|
-
|
108
|
-
assert_equal "bar", r.getset("foo", "baz")
|
109
|
-
assert_equal "baz", r.get("foo")
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_getset_with_non_string_value
|
113
|
-
r.set("foo", "zap")
|
114
|
-
|
115
|
-
value = ["b", "a", "r"]
|
116
|
-
|
117
|
-
assert_equal "zap", r.getset("foo", value)
|
118
|
-
assert_equal value.to_s, r.get("foo")
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_setnx
|
122
|
-
r.set("foo", "qux")
|
123
|
-
assert !r.setnx("foo", "bar")
|
124
|
-
assert_equal "qux", r.get("foo")
|
125
|
-
|
126
|
-
r.del("foo")
|
127
|
-
assert r.setnx("foo", "bar")
|
128
|
-
assert_equal "bar", r.get("foo")
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_setnx_with_non_string_value
|
132
|
-
value = ["b", "a", "r"]
|
133
|
-
|
134
|
-
r.set("foo", "qux")
|
135
|
-
assert !r.setnx("foo", value)
|
136
|
-
assert_equal "qux", r.get("foo")
|
137
|
-
|
138
|
-
r.del("foo")
|
139
|
-
assert r.setnx("foo", value)
|
140
|
-
assert_equal value.to_s, r.get("foo")
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_incr
|
144
|
-
assert_equal 1, r.incr("foo")
|
145
|
-
assert_equal 2, r.incr("foo")
|
146
|
-
assert_equal 3, r.incr("foo")
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_incrby
|
150
|
-
assert_equal 1, r.incrby("foo", 1)
|
151
|
-
assert_equal 3, r.incrby("foo", 2)
|
152
|
-
assert_equal 6, r.incrby("foo", 3)
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_incrbyfloat
|
156
|
-
target_version "2.5.4" do
|
157
|
-
assert_equal 1.23, r.incrbyfloat("foo", 1.23)
|
158
|
-
assert_equal 2 , r.incrbyfloat("foo", 0.77)
|
159
|
-
assert_equal 1.9 , r.incrbyfloat("foo", -0.1)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_decr
|
164
|
-
r.set("foo", 3)
|
165
|
-
|
166
|
-
assert_equal 2, r.decr("foo")
|
167
|
-
assert_equal 1, r.decr("foo")
|
168
|
-
assert_equal 0, r.decr("foo")
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_decrby
|
172
|
-
r.set("foo", 6)
|
173
|
-
|
174
|
-
assert_equal 3, r.decrby("foo", 3)
|
175
|
-
assert_equal 1, r.decrby("foo", 2)
|
176
|
-
assert_equal 0, r.decrby("foo", 1)
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_append
|
180
|
-
r.set "foo", "s"
|
181
|
-
r.append "foo", "1"
|
182
|
-
|
183
|
-
assert_equal "s1", r.get("foo")
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_getbit
|
187
|
-
r.set("foo", "a")
|
188
|
-
|
189
|
-
assert_equal 1, r.getbit("foo", 1)
|
190
|
-
assert_equal 1, r.getbit("foo", 2)
|
191
|
-
assert_equal 0, r.getbit("foo", 3)
|
192
|
-
assert_equal 0, r.getbit("foo", 4)
|
193
|
-
assert_equal 0, r.getbit("foo", 5)
|
194
|
-
assert_equal 0, r.getbit("foo", 6)
|
195
|
-
assert_equal 1, r.getbit("foo", 7)
|
196
|
-
end
|
197
|
-
|
198
|
-
def test_setbit
|
199
|
-
r.set("foo", "a")
|
200
|
-
|
201
|
-
r.setbit("foo", 6, 1)
|
202
|
-
|
203
|
-
assert_equal "c", r.get("foo")
|
204
|
-
end
|
205
|
-
|
206
|
-
def test_bitcount
|
207
|
-
target_version "2.5.10" do
|
208
|
-
r.set("foo", "abcde")
|
209
|
-
|
210
|
-
assert_equal 10, r.bitcount("foo", 1, 3)
|
211
|
-
assert_equal 17, r.bitcount("foo", 0, -1)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_getrange
|
216
|
-
r.set("foo", "abcde")
|
217
|
-
|
218
|
-
assert_equal "bcd", r.getrange("foo", 1, 3)
|
219
|
-
assert_equal "abcde", r.getrange("foo", 0, -1)
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_setrange
|
223
|
-
r.set("foo", "abcde")
|
224
|
-
|
225
|
-
r.setrange("foo", 1, "bar")
|
226
|
-
|
227
|
-
assert_equal "abare", r.get("foo")
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_setrange_with_non_string_value
|
231
|
-
r.set("foo", "abcde")
|
232
|
-
|
233
|
-
value = ["b", "a", "r"]
|
234
|
-
|
235
|
-
r.setrange("foo", 2, value)
|
236
|
-
|
237
|
-
assert_equal "ab#{value.to_s}", r.get("foo")
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_strlen
|
241
|
-
r.set "foo", "lorem"
|
242
|
-
|
243
|
-
assert_equal 5, r.strlen("foo")
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
data/test/lint/value_types.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
module Lint
|
2
|
-
|
3
|
-
module ValueTypes
|
4
|
-
|
5
|
-
def test_exists
|
6
|
-
assert_equal false, r.exists("foo")
|
7
|
-
|
8
|
-
r.set("foo", "s1")
|
9
|
-
|
10
|
-
assert_equal true, r.exists("foo")
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_type
|
14
|
-
assert_equal "none", r.type("foo")
|
15
|
-
|
16
|
-
r.set("foo", "s1")
|
17
|
-
|
18
|
-
assert_equal "string", r.type("foo")
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_keys
|
22
|
-
r.set("f", "s1")
|
23
|
-
r.set("fo", "s2")
|
24
|
-
r.set("foo", "s3")
|
25
|
-
|
26
|
-
assert_equal ["f","fo", "foo"], r.keys("f*").sort
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_expire
|
30
|
-
r.set("foo", "s1")
|
31
|
-
assert r.expire("foo", 2)
|
32
|
-
assert_in_range 0..2, r.ttl("foo")
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_pexpire
|
36
|
-
target_version "2.5.4" do
|
37
|
-
r.set("foo", "s1")
|
38
|
-
assert r.pexpire("foo", 2000)
|
39
|
-
assert_in_range 0..2, r.ttl("foo")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_expireat
|
44
|
-
r.set("foo", "s1")
|
45
|
-
assert r.expireat("foo", (Time.now + 2).to_i)
|
46
|
-
assert_in_range 0..2, r.ttl("foo")
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_pexpireat
|
50
|
-
target_version "2.5.4" do
|
51
|
-
r.set("foo", "s1")
|
52
|
-
assert r.pexpireat("foo", (Time.now + 2).to_i * 1_000)
|
53
|
-
assert_in_range 0..2, r.ttl("foo")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_persist
|
58
|
-
r.set("foo", "s1")
|
59
|
-
r.expire("foo", 1)
|
60
|
-
r.persist("foo")
|
61
|
-
|
62
|
-
assert(-1 == r.ttl("foo"))
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_ttl
|
66
|
-
r.set("foo", "s1")
|
67
|
-
r.expire("foo", 2)
|
68
|
-
assert_in_range 0..2, r.ttl("foo")
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_pttl
|
72
|
-
target_version "2.5.4" do
|
73
|
-
r.set("foo", "s1")
|
74
|
-
r.expire("foo", 2)
|
75
|
-
assert_in_range 1..2000, r.pttl("foo")
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_dump_and_restore
|
80
|
-
target_version "2.5.7" do
|
81
|
-
r.set("foo", "a")
|
82
|
-
v = r.dump("foo")
|
83
|
-
r.del("foo")
|
84
|
-
|
85
|
-
assert r.restore("foo", 1000, v)
|
86
|
-
assert_equal "a", r.get("foo")
|
87
|
-
assert [0, 1].include? r.ttl("foo")
|
88
|
-
|
89
|
-
r.rpush("bar", ["b", "c", "d"])
|
90
|
-
w = r.dump("bar")
|
91
|
-
r.del("bar")
|
92
|
-
|
93
|
-
assert r.restore("bar", 1000, w)
|
94
|
-
assert_equal ["b", "c", "d"], r.lrange("bar", 0, -1)
|
95
|
-
assert [0, 1].include? r.ttl("bar")
|
96
|
-
|
97
|
-
r.set("bar", "somethingelse")
|
98
|
-
assert_raises(Redis::CommandError) { r.restore("bar", 1000, w) } # ensure by default replace is false
|
99
|
-
assert_raises(Redis::CommandError) { r.restore("bar", 1000, w, :replace => false) }
|
100
|
-
assert_equal "somethingelse", r.get("bar")
|
101
|
-
assert r.restore("bar", 1000, w, :replace => true)
|
102
|
-
assert_equal ["b", "c", "d"], r.lrange("bar", 0, -1)
|
103
|
-
assert [0, 1].include? r.ttl("bar")
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_move
|
108
|
-
r.select 14
|
109
|
-
r.flushdb
|
110
|
-
|
111
|
-
r.set "bar", "s3"
|
112
|
-
|
113
|
-
r.select 15
|
114
|
-
|
115
|
-
r.set "foo", "s1"
|
116
|
-
r.set "bar", "s2"
|
117
|
-
|
118
|
-
assert r.move("foo", 14)
|
119
|
-
assert_equal nil, r.get("foo")
|
120
|
-
|
121
|
-
assert !r.move("bar", 14)
|
122
|
-
assert_equal "s2", r.get("bar")
|
123
|
-
|
124
|
-
r.select 14
|
125
|
-
|
126
|
-
assert_equal "s1", r.get("foo")
|
127
|
-
assert_equal "s3", r.get("bar")
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
|
3
|
-
class TestPersistenceControlCommands < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include Helper::Client
|
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,238 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
|
3
|
-
class TestPipeliningCommands < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include Helper::Client
|
6
|
-
|
7
|
-
def test_bulk_commands
|
8
|
-
r.pipelined do
|
9
|
-
r.lpush "foo", "s1"
|
10
|
-
r.lpush "foo", "s2"
|
11
|
-
end
|
12
|
-
|
13
|
-
assert_equal 2, r.llen("foo")
|
14
|
-
assert_equal "s2", r.lpop("foo")
|
15
|
-
assert_equal "s1", r.lpop("foo")
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_multi_bulk_commands
|
19
|
-
r.pipelined do
|
20
|
-
r.mset("foo", "s1", "bar", "s2")
|
21
|
-
r.mset("baz", "s3", "qux", "s4")
|
22
|
-
end
|
23
|
-
|
24
|
-
assert_equal "s1", r.get("foo")
|
25
|
-
assert_equal "s2", r.get("bar")
|
26
|
-
assert_equal "s3", r.get("baz")
|
27
|
-
assert_equal "s4", r.get("qux")
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_bulk_and_multi_bulk_commands_mixed
|
31
|
-
r.pipelined do
|
32
|
-
r.lpush "foo", "s1"
|
33
|
-
r.lpush "foo", "s2"
|
34
|
-
r.mset("baz", "s3", "qux", "s4")
|
35
|
-
end
|
36
|
-
|
37
|
-
assert_equal 2, r.llen("foo")
|
38
|
-
assert_equal "s2", r.lpop("foo")
|
39
|
-
assert_equal "s1", r.lpop("foo")
|
40
|
-
assert_equal "s3", r.get("baz")
|
41
|
-
assert_equal "s4", r.get("qux")
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_multi_bulk_and_bulk_commands_mixed
|
45
|
-
r.pipelined do
|
46
|
-
r.mset("baz", "s3", "qux", "s4")
|
47
|
-
r.lpush "foo", "s1"
|
48
|
-
r.lpush "foo", "s2"
|
49
|
-
end
|
50
|
-
|
51
|
-
assert_equal 2, r.llen("foo")
|
52
|
-
assert_equal "s2", r.lpop("foo")
|
53
|
-
assert_equal "s1", r.lpop("foo")
|
54
|
-
assert_equal "s3", r.get("baz")
|
55
|
-
assert_equal "s4", r.get("qux")
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_pipelined_with_an_empty_block
|
59
|
-
assert_nothing_raised do
|
60
|
-
r.pipelined do
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
assert_equal 0, r.dbsize
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_returning_the_result_of_a_pipeline
|
68
|
-
result = r.pipelined do
|
69
|
-
r.set "foo", "bar"
|
70
|
-
r.get "foo"
|
71
|
-
r.get "bar"
|
72
|
-
end
|
73
|
-
|
74
|
-
assert_equal ["OK", "bar", nil], result
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_assignment_of_results_inside_the_block
|
78
|
-
r.pipelined do
|
79
|
-
@first = r.sadd("foo", 1)
|
80
|
-
@second = r.sadd("foo", 1)
|
81
|
-
end
|
82
|
-
|
83
|
-
assert_equal true, @first.value
|
84
|
-
assert_equal false, @second.value
|
85
|
-
end
|
86
|
-
|
87
|
-
# Although we could support accessing the values in these futures,
|
88
|
-
# it doesn't make a lot of sense.
|
89
|
-
def test_assignment_of_results_inside_the_block_with_errors
|
90
|
-
assert_raise(Redis::CommandError) do
|
91
|
-
r.pipelined do
|
92
|
-
r.doesnt_exist
|
93
|
-
@first = r.sadd("foo", 1)
|
94
|
-
@second = r.sadd("foo", 1)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
assert_raise(Redis::FutureNotReady) { @first.value }
|
99
|
-
assert_raise(Redis::FutureNotReady) { @second.value }
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_assignment_of_results_inside_a_nested_block
|
103
|
-
r.pipelined do
|
104
|
-
@first = r.sadd("foo", 1)
|
105
|
-
|
106
|
-
r.pipelined do
|
107
|
-
@second = r.sadd("foo", 1)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
assert_equal true, @first.value
|
112
|
-
assert_equal false, @second.value
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_futures_raise_when_confused_with_something_else
|
116
|
-
r.pipelined do
|
117
|
-
@result = r.sadd("foo", 1)
|
118
|
-
end
|
119
|
-
|
120
|
-
assert_raise(NoMethodError) { @result.to_s }
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_futures_raise_when_trying_to_access_their_values_too_early
|
124
|
-
r.pipelined do
|
125
|
-
assert_raise(Redis::FutureNotReady) do
|
126
|
-
r.sadd("foo", 1).value
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_futures_can_be_identified
|
132
|
-
r.pipelined do
|
133
|
-
@result = r.sadd("foo", 1)
|
134
|
-
end
|
135
|
-
|
136
|
-
assert_equal true, @result.is_a?(Redis::Future)
|
137
|
-
assert_equal true, @result.is_a?(::BasicObject)
|
138
|
-
assert_equal Redis::Future, @result.class
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_returning_the_result_of_an_empty_pipeline
|
142
|
-
result = r.pipelined do
|
143
|
-
end
|
144
|
-
|
145
|
-
assert_equal [], result
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_nesting_pipeline_blocks
|
149
|
-
r.pipelined do
|
150
|
-
r.set("foo", "s1")
|
151
|
-
r.pipelined do
|
152
|
-
r.set("bar", "s2")
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
assert_equal "s1", r.get("foo")
|
157
|
-
assert_equal "s2", r.get("bar")
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_info_in_a_pipeline_returns_hash
|
161
|
-
result = r.pipelined do
|
162
|
-
r.info
|
163
|
-
end
|
164
|
-
|
165
|
-
assert result.first.kind_of?(Hash)
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_config_get_in_a_pipeline_returns_hash
|
169
|
-
result = r.pipelined do
|
170
|
-
r.config(:get, "*")
|
171
|
-
end
|
172
|
-
|
173
|
-
assert result.first.kind_of?(Hash)
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_hgetall_in_a_pipeline_returns_hash
|
177
|
-
r.hmset("hash", "field", "value")
|
178
|
-
result = r.pipelined do
|
179
|
-
r.hgetall("hash")
|
180
|
-
end
|
181
|
-
|
182
|
-
assert_equal result.first, { "field" => "value" }
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_keys_in_a_pipeline
|
186
|
-
r.set("key", "value")
|
187
|
-
result = r.pipelined do
|
188
|
-
r.keys("*")
|
189
|
-
end
|
190
|
-
|
191
|
-
assert_equal ["key"], result.first
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_pipeline_yields_a_connection
|
195
|
-
r.pipelined do |p|
|
196
|
-
p.set("foo", "bar")
|
197
|
-
end
|
198
|
-
|
199
|
-
assert_equal "bar", r.get("foo")
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_pipeline_select
|
203
|
-
r.select 1
|
204
|
-
r.set("db", "1")
|
205
|
-
|
206
|
-
r.pipelined do |p|
|
207
|
-
p.select 2
|
208
|
-
p.set("db", "2")
|
209
|
-
end
|
210
|
-
|
211
|
-
r.select 1
|
212
|
-
assert_equal "1", r.get("db")
|
213
|
-
|
214
|
-
r.select 2
|
215
|
-
assert_equal "2", r.get("db")
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_pipeline_select_client_db
|
219
|
-
r.select 1
|
220
|
-
r.pipelined do |p2|
|
221
|
-
p2.select 2
|
222
|
-
end
|
223
|
-
|
224
|
-
assert_equal 2, r._client.db
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_nested_pipeline_select_client_db
|
228
|
-
r.select 1
|
229
|
-
r.pipelined do |p2|
|
230
|
-
p2.select 2
|
231
|
-
p2.pipelined do |p3|
|
232
|
-
p3.select 3
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
assert_equal 3, r._client.db
|
237
|
-
end
|
238
|
-
end
|