redis2-namespaced 3.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.order +170 -0
- data/.travis/Gemfile +11 -0
- data/.travis.yml +55 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +285 -0
- data/LICENSE +20 -0
- data/README.md +251 -0
- data/Rakefile +403 -0
- data/benchmarking/logging.rb +71 -0
- data/benchmarking/pipeline.rb +51 -0
- data/benchmarking/speed.rb +21 -0
- data/benchmarking/suite.rb +24 -0
- data/benchmarking/worker.rb +71 -0
- data/examples/basic.rb +15 -0
- data/examples/dist_redis.rb +43 -0
- data/examples/incr-decr.rb +17 -0
- data/examples/list.rb +26 -0
- data/examples/pubsub.rb +37 -0
- data/examples/sets.rb +36 -0
- data/examples/unicorn/config.ru +3 -0
- data/examples/unicorn/unicorn.rb +20 -0
- data/lib/redis2/client.rb +419 -0
- data/lib/redis2/connection/command_helper.rb +44 -0
- data/lib/redis2/connection/hiredis.rb +63 -0
- data/lib/redis2/connection/registry.rb +12 -0
- data/lib/redis2/connection/ruby.rb +322 -0
- data/lib/redis2/connection/synchrony.rb +124 -0
- data/lib/redis2/connection.rb +9 -0
- data/lib/redis2/distributed.rb +853 -0
- data/lib/redis2/errors.rb +40 -0
- data/lib/redis2/hash_ring.rb +131 -0
- data/lib/redis2/pipeline.rb +141 -0
- data/lib/redis2/subscribe.rb +83 -0
- data/lib/redis2/version.rb +3 -0
- data/lib/redis2.rb +2533 -0
- data/redis.gemspec +43 -0
- data/test/bitpos_test.rb +69 -0
- data/test/blocking_commands_test.rb +42 -0
- data/test/command_map_test.rb +30 -0
- data/test/commands_on_hashes_test.rb +21 -0
- data/test/commands_on_lists_test.rb +20 -0
- data/test/commands_on_sets_test.rb +77 -0
- data/test/commands_on_sorted_sets_test.rb +109 -0
- data/test/commands_on_strings_test.rb +101 -0
- data/test/commands_on_value_types_test.rb +131 -0
- data/test/connection_handling_test.rb +189 -0
- data/test/db/.gitkeep +0 -0
- data/test/distributed_blocking_commands_test.rb +46 -0
- data/test/distributed_commands_on_hashes_test.rb +10 -0
- data/test/distributed_commands_on_lists_test.rb +22 -0
- data/test/distributed_commands_on_sets_test.rb +83 -0
- data/test/distributed_commands_on_sorted_sets_test.rb +18 -0
- data/test/distributed_commands_on_strings_test.rb +59 -0
- data/test/distributed_commands_on_value_types_test.rb +95 -0
- data/test/distributed_commands_requiring_clustering_test.rb +164 -0
- data/test/distributed_connection_handling_test.rb +23 -0
- data/test/distributed_internals_test.rb +70 -0
- data/test/distributed_key_tags_test.rb +52 -0
- data/test/distributed_persistence_control_commands_test.rb +26 -0
- data/test/distributed_publish_subscribe_test.rb +92 -0
- data/test/distributed_remote_server_control_commands_test.rb +66 -0
- data/test/distributed_scripting_test.rb +102 -0
- data/test/distributed_sorting_test.rb +20 -0
- data/test/distributed_test.rb +58 -0
- data/test/distributed_transactions_test.rb +32 -0
- data/test/encoding_test.rb +18 -0
- data/test/error_replies_test.rb +59 -0
- data/test/helper.rb +218 -0
- data/test/helper_test.rb +24 -0
- data/test/internals_test.rb +410 -0
- data/test/lint/blocking_commands.rb +150 -0
- data/test/lint/hashes.rb +162 -0
- data/test/lint/lists.rb +143 -0
- data/test/lint/sets.rb +125 -0
- data/test/lint/sorted_sets.rb +238 -0
- data/test/lint/strings.rb +260 -0
- data/test/lint/value_types.rb +122 -0
- data/test/persistence_control_commands_test.rb +26 -0
- data/test/pipelining_commands_test.rb +242 -0
- data/test/publish_subscribe_test.rb +210 -0
- data/test/remote_server_control_commands_test.rb +117 -0
- data/test/scanning_test.rb +413 -0
- data/test/scripting_test.rb +78 -0
- data/test/sorting_test.rb +59 -0
- 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/support/redis_mock.rb +115 -0
- data/test/support/wire/synchrony.rb +24 -0
- data/test/support/wire/thread.rb +5 -0
- data/test/synchrony_driver.rb +88 -0
- data/test/test.conf +9 -0
- data/test/thread_safety_test.rb +32 -0
- data/test/transactions_test.rb +264 -0
- data/test/unknown_commands_test.rb +14 -0
- data/test/url_param_test.rb +132 -0
- metadata +226 -0
@@ -0,0 +1,238 @@
|
|
1
|
+
module Lint
|
2
|
+
|
3
|
+
module SortedSets
|
4
|
+
|
5
|
+
Infinity = 1.0/0.0
|
6
|
+
|
7
|
+
def test_zadd
|
8
|
+
assert_equal 0, r.zcard("foo")
|
9
|
+
assert_equal true, r.zadd("foo", 1, "s1")
|
10
|
+
assert_equal false, r.zadd("foo", 1, "s1")
|
11
|
+
assert_equal 1, r.zcard("foo")
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_variadic_zadd
|
15
|
+
target_version "2.3.9" do # 2.4-rc6
|
16
|
+
# Non-nested array with pairs
|
17
|
+
assert_equal 0, r.zcard("foo")
|
18
|
+
assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"])
|
19
|
+
assert_equal 1, r.zadd("foo", [4, "s1", 5, "s2", 6, "s3"])
|
20
|
+
assert_equal 3, r.zcard("foo")
|
21
|
+
r.del "foo"
|
22
|
+
|
23
|
+
# Nested array with pairs
|
24
|
+
assert_equal 0, r.zcard("foo")
|
25
|
+
assert_equal 2, r.zadd("foo", [[1, "s1"], [2, "s2"]])
|
26
|
+
assert_equal 1, r.zadd("foo", [[4, "s1"], [5, "s2"], [6, "s3"]])
|
27
|
+
assert_equal 3, r.zcard("foo")
|
28
|
+
r.del "foo"
|
29
|
+
|
30
|
+
# Wrong number of arguments
|
31
|
+
assert_raise(Redis2::CommandError) { r.zadd("foo", ["bar"]) }
|
32
|
+
assert_raise(Redis2::CommandError) { r.zadd("foo", ["bar", "qux", "zap"]) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_zrem
|
37
|
+
r.zadd("foo", 1, "s1")
|
38
|
+
r.zadd("foo", 2, "s2")
|
39
|
+
|
40
|
+
assert_equal 2, r.zcard("foo")
|
41
|
+
assert_equal true, r.zrem("foo", "s1")
|
42
|
+
assert_equal false, r.zrem("foo", "s1")
|
43
|
+
assert_equal 1, r.zcard("foo")
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_variadic_zrem
|
47
|
+
target_version "2.3.9" do # 2.4-rc6
|
48
|
+
r.zadd("foo", 1, "s1")
|
49
|
+
r.zadd("foo", 2, "s2")
|
50
|
+
r.zadd("foo", 3, "s3")
|
51
|
+
|
52
|
+
assert_equal 3, r.zcard("foo")
|
53
|
+
assert_equal 1, r.zrem("foo", ["s1", "aaa"])
|
54
|
+
assert_equal 0, r.zrem("foo", ["bbb", "ccc" "ddd"])
|
55
|
+
assert_equal 1, r.zrem("foo", ["eee", "s3"])
|
56
|
+
assert_equal 1, r.zcard("foo")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_zincrby
|
61
|
+
rv = r.zincrby "foo", 1, "s1"
|
62
|
+
assert_equal 1.0, rv
|
63
|
+
|
64
|
+
rv = r.zincrby "foo", 10, "s1"
|
65
|
+
assert_equal 11.0, rv
|
66
|
+
|
67
|
+
rv = r.zincrby "bar", "-inf", "s1"
|
68
|
+
assert_equal(-Infinity, rv)
|
69
|
+
|
70
|
+
rv = r.zincrby "bar", "+inf", "s2"
|
71
|
+
assert_equal(+Infinity, rv)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_zrank
|
75
|
+
r.zadd "foo", 1, "s1"
|
76
|
+
r.zadd "foo", 2, "s2"
|
77
|
+
r.zadd "foo", 3, "s3"
|
78
|
+
|
79
|
+
assert_equal 2, r.zrank("foo", "s3")
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_zrevrank
|
83
|
+
r.zadd "foo", 1, "s1"
|
84
|
+
r.zadd "foo", 2, "s2"
|
85
|
+
r.zadd "foo", 3, "s3"
|
86
|
+
|
87
|
+
assert_equal 0, r.zrevrank("foo", "s3")
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_zrange
|
91
|
+
r.zadd "foo", 1, "s1"
|
92
|
+
r.zadd "foo", 2, "s2"
|
93
|
+
r.zadd "foo", 3, "s3"
|
94
|
+
|
95
|
+
assert_equal ["s1", "s2"], r.zrange("foo", 0, 1)
|
96
|
+
assert_equal [["s1", 1.0], ["s2", 2.0]], r.zrange("foo", 0, 1, :with_scores => true)
|
97
|
+
assert_equal [["s1", 1.0], ["s2", 2.0]], r.zrange("foo", 0, 1, :withscores => true)
|
98
|
+
|
99
|
+
r.zadd "bar", "-inf", "s1"
|
100
|
+
r.zadd "bar", "+inf", "s2"
|
101
|
+
assert_equal [["s1", -Infinity], ["s2", +Infinity]], r.zrange("bar", 0, 1, :with_scores => true)
|
102
|
+
assert_equal [["s1", -Infinity], ["s2", +Infinity]], r.zrange("bar", 0, 1, :withscores => true)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_zrevrange
|
106
|
+
r.zadd "foo", 1, "s1"
|
107
|
+
r.zadd "foo", 2, "s2"
|
108
|
+
r.zadd "foo", 3, "s3"
|
109
|
+
|
110
|
+
assert_equal ["s3", "s2"], r.zrevrange("foo", 0, 1)
|
111
|
+
assert_equal [["s3", 3.0], ["s2", 2.0]], r.zrevrange("foo", 0, 1, :with_scores => true)
|
112
|
+
assert_equal [["s3", 3.0], ["s2", 2.0]], r.zrevrange("foo", 0, 1, :withscores => true)
|
113
|
+
|
114
|
+
r.zadd "bar", "-inf", "s1"
|
115
|
+
r.zadd "bar", "+inf", "s2"
|
116
|
+
assert_equal [["s2", +Infinity], ["s1", -Infinity]], r.zrevrange("bar", 0, 1, :with_scores => true)
|
117
|
+
assert_equal [["s2", +Infinity], ["s1", -Infinity]], r.zrevrange("bar", 0, 1, :withscores => true)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_zrangebyscore
|
121
|
+
r.zadd "foo", 1, "s1"
|
122
|
+
r.zadd "foo", 2, "s2"
|
123
|
+
r.zadd "foo", 3, "s3"
|
124
|
+
|
125
|
+
assert_equal ["s2", "s3"], r.zrangebyscore("foo", 2, 3)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_zrevrangebyscore
|
129
|
+
r.zadd "foo", 1, "s1"
|
130
|
+
r.zadd "foo", 2, "s2"
|
131
|
+
r.zadd "foo", 3, "s3"
|
132
|
+
|
133
|
+
assert_equal ["s3", "s2"], r.zrevrangebyscore("foo", 3, 2)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_zrangebyscore_with_limit
|
137
|
+
r.zadd "foo", 1, "s1"
|
138
|
+
r.zadd "foo", 2, "s2"
|
139
|
+
r.zadd "foo", 3, "s3"
|
140
|
+
r.zadd "foo", 4, "s4"
|
141
|
+
|
142
|
+
assert_equal ["s2"], r.zrangebyscore("foo", 2, 4, :limit => [0, 1])
|
143
|
+
assert_equal ["s3"], r.zrangebyscore("foo", 2, 4, :limit => [1, 1])
|
144
|
+
assert_equal ["s3", "s4"], r.zrangebyscore("foo", 2, 4, :limit => [1, 2])
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_zrevrangebyscore_with_limit
|
148
|
+
r.zadd "foo", 1, "s1"
|
149
|
+
r.zadd "foo", 2, "s2"
|
150
|
+
r.zadd "foo", 3, "s3"
|
151
|
+
r.zadd "foo", 4, "s4"
|
152
|
+
|
153
|
+
assert_equal ["s4"], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1])
|
154
|
+
assert_equal ["s3"], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1])
|
155
|
+
assert_equal ["s3", "s2"], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 2])
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_zrangebyscore_with_withscores
|
159
|
+
r.zadd "foo", 1, "s1"
|
160
|
+
r.zadd "foo", 2, "s2"
|
161
|
+
r.zadd "foo", 3, "s3"
|
162
|
+
r.zadd "foo", 4, "s4"
|
163
|
+
|
164
|
+
assert_equal [["s2", 2.0]], r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :with_scores => true)
|
165
|
+
assert_equal [["s3", 3.0]], r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :with_scores => true)
|
166
|
+
assert_equal [["s2", 2.0]], r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :withscores => true)
|
167
|
+
assert_equal [["s3", 3.0]], r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :withscores => true)
|
168
|
+
|
169
|
+
r.zadd "bar", "-inf", "s1"
|
170
|
+
r.zadd "bar", "+inf", "s2"
|
171
|
+
assert_equal [["s1", -Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [0, 1], :with_scores => true)
|
172
|
+
assert_equal [["s2", +Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [1, 1], :with_scores => true)
|
173
|
+
assert_equal [["s1", -Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [0, 1], :withscores => true)
|
174
|
+
assert_equal [["s2", +Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [1, 1], :withscores => true)
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_zrevrangebyscore_with_withscores
|
178
|
+
r.zadd "foo", 1, "s1"
|
179
|
+
r.zadd "foo", 2, "s2"
|
180
|
+
r.zadd "foo", 3, "s3"
|
181
|
+
r.zadd "foo", 4, "s4"
|
182
|
+
|
183
|
+
assert_equal [["s4", 4.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :with_scores => true)
|
184
|
+
assert_equal [["s3", 3.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :with_scores => true)
|
185
|
+
assert_equal [["s4", 4.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :withscores => true)
|
186
|
+
assert_equal [["s3", 3.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :withscores => true)
|
187
|
+
|
188
|
+
r.zadd "bar", "-inf", "s1"
|
189
|
+
r.zadd "bar", "+inf", "s2"
|
190
|
+
assert_equal [["s2", +Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [0, 1], :with_scores => true)
|
191
|
+
assert_equal [["s1", -Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [1, 1], :with_scores => true)
|
192
|
+
assert_equal [["s2", +Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [0, 1], :withscores => true)
|
193
|
+
assert_equal [["s1", -Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [1, 1], :withscores => true)
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_zcard
|
197
|
+
assert_equal 0, r.zcard("foo")
|
198
|
+
|
199
|
+
r.zadd "foo", 1, "s1"
|
200
|
+
|
201
|
+
assert_equal 1, r.zcard("foo")
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_zscore
|
205
|
+
r.zadd "foo", 1, "s1"
|
206
|
+
|
207
|
+
assert_equal 1.0, r.zscore("foo", "s1")
|
208
|
+
|
209
|
+
assert_equal nil, r.zscore("foo", "s2")
|
210
|
+
assert_equal nil, r.zscore("bar", "s1")
|
211
|
+
|
212
|
+
r.zadd "bar", "-inf", "s1"
|
213
|
+
r.zadd "bar", "+inf", "s2"
|
214
|
+
assert_equal(-Infinity, r.zscore("bar", "s1"))
|
215
|
+
assert_equal(+Infinity, r.zscore("bar", "s2"))
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_zremrangebyrank
|
219
|
+
r.zadd "foo", 10, "s1"
|
220
|
+
r.zadd "foo", 20, "s2"
|
221
|
+
r.zadd "foo", 30, "s3"
|
222
|
+
r.zadd "foo", 40, "s4"
|
223
|
+
|
224
|
+
assert_equal 3, r.zremrangebyrank("foo", 1, 3)
|
225
|
+
assert_equal ["s1"], r.zrange("foo", 0, -1)
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_zremrangebyscore
|
229
|
+
r.zadd "foo", 1, "s1"
|
230
|
+
r.zadd "foo", 2, "s2"
|
231
|
+
r.zadd "foo", 3, "s3"
|
232
|
+
r.zadd "foo", 4, "s4"
|
233
|
+
|
234
|
+
assert_equal 3, r.zremrangebyscore("foo", 2, 4)
|
235
|
+
assert_equal ["s1"], r.zrange("foo", 0, -1)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
@@ -0,0 +1,260 @@
|
|
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_brackets
|
12
|
+
r["foo"] = "s1"
|
13
|
+
|
14
|
+
assert_equal "s1", r["foo"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_set_and_get_with_brackets_and_symbol
|
18
|
+
r[:foo] = "s1"
|
19
|
+
|
20
|
+
assert_equal "s1", r[:foo]
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_set_and_get_with_newline_characters
|
24
|
+
r.set("foo", "1\n")
|
25
|
+
|
26
|
+
assert_equal "1\n", r.get("foo")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_set_and_get_with_non_string_value
|
30
|
+
value = ["a", "b"]
|
31
|
+
|
32
|
+
r.set("foo", value)
|
33
|
+
|
34
|
+
assert_equal value.to_s, r.get("foo")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_set_and_get_with_ascii_characters
|
38
|
+
if defined?(Encoding)
|
39
|
+
with_external_encoding("ASCII-8BIT") do
|
40
|
+
(0..255).each do |i|
|
41
|
+
str = "#{i.chr}---#{i.chr}"
|
42
|
+
r.set("foo", str)
|
43
|
+
|
44
|
+
assert_equal str, r.get("foo")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_set_with_ex
|
51
|
+
target_version "2.6.12" do
|
52
|
+
r.set("foo", "bar", :ex => 2)
|
53
|
+
assert_in_range 0..2, r.ttl("foo")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_set_with_px
|
58
|
+
target_version "2.6.12" do
|
59
|
+
r.set("foo", "bar", :px => 2000)
|
60
|
+
assert_in_range 0..2, r.ttl("foo")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_set_with_nx
|
65
|
+
target_version "2.6.12" do
|
66
|
+
r.set("foo", "qux", :nx => true)
|
67
|
+
assert !r.set("foo", "bar", :nx => true)
|
68
|
+
assert_equal "qux", r.get("foo")
|
69
|
+
|
70
|
+
r.del("foo")
|
71
|
+
assert r.set("foo", "bar", :nx => true)
|
72
|
+
assert_equal "bar", r.get("foo")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_set_with_xx
|
77
|
+
target_version "2.6.12" do
|
78
|
+
r.set("foo", "qux")
|
79
|
+
assert r.set("foo", "bar", :xx => true)
|
80
|
+
assert_equal "bar", r.get("foo")
|
81
|
+
|
82
|
+
r.del("foo")
|
83
|
+
assert !r.set("foo", "bar", :xx => true)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_setex
|
88
|
+
assert r.setex("foo", 1, "bar")
|
89
|
+
assert_equal "bar", r.get("foo")
|
90
|
+
assert [0, 1].include? r.ttl("foo")
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_setex_with_non_string_value
|
94
|
+
value = ["b", "a", "r"]
|
95
|
+
|
96
|
+
assert r.setex("foo", 1, value)
|
97
|
+
assert_equal value.to_s, r.get("foo")
|
98
|
+
assert [0, 1].include? r.ttl("foo")
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_psetex
|
102
|
+
target_version "2.5.4" do
|
103
|
+
assert r.psetex("foo", 1000, "bar")
|
104
|
+
assert_equal "bar", r.get("foo")
|
105
|
+
assert [0, 1].include? r.ttl("foo")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_psetex_with_non_string_value
|
110
|
+
target_version "2.5.4" do
|
111
|
+
value = ["b", "a", "r"]
|
112
|
+
|
113
|
+
assert r.psetex("foo", 1000, value)
|
114
|
+
assert_equal value.to_s, r.get("foo")
|
115
|
+
assert [0, 1].include? r.ttl("foo")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_getset
|
120
|
+
r.set("foo", "bar")
|
121
|
+
|
122
|
+
assert_equal "bar", r.getset("foo", "baz")
|
123
|
+
assert_equal "baz", r.get("foo")
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_getset_with_non_string_value
|
127
|
+
r.set("foo", "zap")
|
128
|
+
|
129
|
+
value = ["b", "a", "r"]
|
130
|
+
|
131
|
+
assert_equal "zap", r.getset("foo", value)
|
132
|
+
assert_equal value.to_s, r.get("foo")
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_setnx
|
136
|
+
r.set("foo", "qux")
|
137
|
+
assert !r.setnx("foo", "bar")
|
138
|
+
assert_equal "qux", r.get("foo")
|
139
|
+
|
140
|
+
r.del("foo")
|
141
|
+
assert r.setnx("foo", "bar")
|
142
|
+
assert_equal "bar", r.get("foo")
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_setnx_with_non_string_value
|
146
|
+
value = ["b", "a", "r"]
|
147
|
+
|
148
|
+
r.set("foo", "qux")
|
149
|
+
assert !r.setnx("foo", value)
|
150
|
+
assert_equal "qux", r.get("foo")
|
151
|
+
|
152
|
+
r.del("foo")
|
153
|
+
assert r.setnx("foo", value)
|
154
|
+
assert_equal value.to_s, r.get("foo")
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_incr
|
158
|
+
assert_equal 1, r.incr("foo")
|
159
|
+
assert_equal 2, r.incr("foo")
|
160
|
+
assert_equal 3, r.incr("foo")
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_incrby
|
164
|
+
assert_equal 1, r.incrby("foo", 1)
|
165
|
+
assert_equal 3, r.incrby("foo", 2)
|
166
|
+
assert_equal 6, r.incrby("foo", 3)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_incrbyfloat
|
170
|
+
target_version "2.5.4" do
|
171
|
+
assert_equal 1.23, r.incrbyfloat("foo", 1.23)
|
172
|
+
assert_equal 2 , r.incrbyfloat("foo", 0.77)
|
173
|
+
assert_equal 1.9 , r.incrbyfloat("foo", -0.1)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_decr
|
178
|
+
r.set("foo", 3)
|
179
|
+
|
180
|
+
assert_equal 2, r.decr("foo")
|
181
|
+
assert_equal 1, r.decr("foo")
|
182
|
+
assert_equal 0, r.decr("foo")
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_decrby
|
186
|
+
r.set("foo", 6)
|
187
|
+
|
188
|
+
assert_equal 3, r.decrby("foo", 3)
|
189
|
+
assert_equal 1, r.decrby("foo", 2)
|
190
|
+
assert_equal 0, r.decrby("foo", 1)
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_append
|
194
|
+
r.set "foo", "s"
|
195
|
+
r.append "foo", "1"
|
196
|
+
|
197
|
+
assert_equal "s1", r.get("foo")
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_getbit
|
201
|
+
r.set("foo", "a")
|
202
|
+
|
203
|
+
assert_equal 1, r.getbit("foo", 1)
|
204
|
+
assert_equal 1, r.getbit("foo", 2)
|
205
|
+
assert_equal 0, r.getbit("foo", 3)
|
206
|
+
assert_equal 0, r.getbit("foo", 4)
|
207
|
+
assert_equal 0, r.getbit("foo", 5)
|
208
|
+
assert_equal 0, r.getbit("foo", 6)
|
209
|
+
assert_equal 1, r.getbit("foo", 7)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_setbit
|
213
|
+
r.set("foo", "a")
|
214
|
+
|
215
|
+
r.setbit("foo", 6, 1)
|
216
|
+
|
217
|
+
assert_equal "c", r.get("foo")
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_bitcount
|
221
|
+
target_version "2.5.10" do
|
222
|
+
r.set("foo", "abcde")
|
223
|
+
|
224
|
+
assert_equal 10, r.bitcount("foo", 1, 3)
|
225
|
+
assert_equal 17, r.bitcount("foo", 0, -1)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_getrange
|
230
|
+
r.set("foo", "abcde")
|
231
|
+
|
232
|
+
assert_equal "bcd", r.getrange("foo", 1, 3)
|
233
|
+
assert_equal "abcde", r.getrange("foo", 0, -1)
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_setrange
|
237
|
+
r.set("foo", "abcde")
|
238
|
+
|
239
|
+
r.setrange("foo", 1, "bar")
|
240
|
+
|
241
|
+
assert_equal "abare", r.get("foo")
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_setrange_with_non_string_value
|
245
|
+
r.set("foo", "abcde")
|
246
|
+
|
247
|
+
value = ["b", "a", "r"]
|
248
|
+
|
249
|
+
r.setrange("foo", 2, value)
|
250
|
+
|
251
|
+
assert_equal "ab#{value.to_s}", r.get("foo")
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_strlen
|
255
|
+
r.set "foo", "lorem"
|
256
|
+
|
257
|
+
assert_equal 5, r.strlen("foo")
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
@@ -0,0 +1,122 @@
|
|
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
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_move
|
100
|
+
r.select 14
|
101
|
+
r.flushdb
|
102
|
+
|
103
|
+
r.set "bar", "s3"
|
104
|
+
|
105
|
+
r.select 15
|
106
|
+
|
107
|
+
r.set "foo", "s1"
|
108
|
+
r.set "bar", "s2"
|
109
|
+
|
110
|
+
assert r.move("foo", 14)
|
111
|
+
assert_equal nil, r.get("foo")
|
112
|
+
|
113
|
+
assert !r.move("bar", 14)
|
114
|
+
assert_equal "s2", r.get("bar")
|
115
|
+
|
116
|
+
r.select 14
|
117
|
+
|
118
|
+
assert_equal "s1", r.get("foo")
|
119
|
+
assert_equal "s3", r.get("bar")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
class TestPersistenceControlCommands < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Helper::Client
|
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
|