redis 4.1.0.beta1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -2
  3. data/README.md +45 -0
  4. data/lib/redis.rb +497 -20
  5. data/lib/redis/client.rb +14 -6
  6. data/lib/redis/cluster.rb +1 -0
  7. data/lib/redis/cluster/command_loader.rb +2 -0
  8. data/lib/redis/cluster/node_loader.rb +2 -0
  9. data/lib/redis/cluster/option.rb +1 -0
  10. data/lib/redis/cluster/slot_loader.rb +2 -0
  11. data/lib/redis/distributed.rb +3 -4
  12. data/lib/redis/version.rb +1 -1
  13. metadata +20 -243
  14. data/.gitignore +0 -19
  15. data/.travis.yml +0 -61
  16. data/.travis/Gemfile +0 -18
  17. data/.yardopts +0 -3
  18. data/Gemfile +0 -8
  19. data/benchmarking/logging.rb +0 -71
  20. data/benchmarking/pipeline.rb +0 -51
  21. data/benchmarking/speed.rb +0 -21
  22. data/benchmarking/suite.rb +0 -24
  23. data/benchmarking/worker.rb +0 -71
  24. data/bin/build +0 -71
  25. data/bors.toml +0 -14
  26. data/examples/basic.rb +0 -15
  27. data/examples/consistency.rb +0 -114
  28. data/examples/dist_redis.rb +0 -43
  29. data/examples/incr-decr.rb +0 -17
  30. data/examples/list.rb +0 -26
  31. data/examples/pubsub.rb +0 -37
  32. data/examples/sentinel.rb +0 -41
  33. data/examples/sentinel/start +0 -49
  34. data/examples/sets.rb +0 -36
  35. data/examples/unicorn/config.ru +0 -3
  36. data/examples/unicorn/unicorn.rb +0 -20
  37. data/makefile +0 -74
  38. data/redis.gemspec +0 -42
  39. data/test/bitpos_test.rb +0 -63
  40. data/test/blocking_commands_test.rb +0 -40
  41. data/test/client_test.rb +0 -76
  42. data/test/cluster_abnormal_state_test.rb +0 -38
  43. data/test/cluster_blocking_commands_test.rb +0 -15
  44. data/test/cluster_client_internals_test.rb +0 -77
  45. data/test/cluster_client_key_hash_tags_test.rb +0 -88
  46. data/test/cluster_client_options_test.rb +0 -147
  47. data/test/cluster_client_pipelining_test.rb +0 -59
  48. data/test/cluster_client_replicas_test.rb +0 -36
  49. data/test/cluster_client_slots_test.rb +0 -94
  50. data/test/cluster_client_transactions_test.rb +0 -71
  51. data/test/cluster_commands_on_cluster_test.rb +0 -165
  52. data/test/cluster_commands_on_connection_test.rb +0 -40
  53. data/test/cluster_commands_on_geo_test.rb +0 -74
  54. data/test/cluster_commands_on_hashes_test.rb +0 -11
  55. data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
  56. data/test/cluster_commands_on_keys_test.rb +0 -134
  57. data/test/cluster_commands_on_lists_test.rb +0 -15
  58. data/test/cluster_commands_on_pub_sub_test.rb +0 -101
  59. data/test/cluster_commands_on_scripting_test.rb +0 -56
  60. data/test/cluster_commands_on_server_test.rb +0 -221
  61. data/test/cluster_commands_on_sets_test.rb +0 -39
  62. data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
  63. data/test/cluster_commands_on_streams_test.rb +0 -196
  64. data/test/cluster_commands_on_strings_test.rb +0 -15
  65. data/test/cluster_commands_on_transactions_test.rb +0 -41
  66. data/test/cluster_commands_on_value_types_test.rb +0 -14
  67. data/test/command_map_test.rb +0 -28
  68. data/test/commands_on_geo_test.rb +0 -116
  69. data/test/commands_on_hashes_test.rb +0 -7
  70. data/test/commands_on_hyper_log_log_test.rb +0 -7
  71. data/test/commands_on_lists_test.rb +0 -7
  72. data/test/commands_on_sets_test.rb +0 -7
  73. data/test/commands_on_sorted_sets_test.rb +0 -7
  74. data/test/commands_on_strings_test.rb +0 -7
  75. data/test/commands_on_value_types_test.rb +0 -207
  76. data/test/connection_handling_test.rb +0 -275
  77. data/test/connection_test.rb +0 -57
  78. data/test/distributed_blocking_commands_test.rb +0 -52
  79. data/test/distributed_commands_on_hashes_test.rb +0 -21
  80. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
  81. data/test/distributed_commands_on_lists_test.rb +0 -19
  82. data/test/distributed_commands_on_sets_test.rb +0 -105
  83. data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
  84. data/test/distributed_commands_on_strings_test.rb +0 -79
  85. data/test/distributed_commands_on_value_types_test.rb +0 -129
  86. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  87. data/test/distributed_connection_handling_test.rb +0 -21
  88. data/test/distributed_internals_test.rb +0 -68
  89. data/test/distributed_key_tags_test.rb +0 -50
  90. data/test/distributed_persistence_control_commands_test.rb +0 -24
  91. data/test/distributed_publish_subscribe_test.rb +0 -90
  92. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  93. data/test/distributed_scripting_test.rb +0 -100
  94. data/test/distributed_sorting_test.rb +0 -18
  95. data/test/distributed_test.rb +0 -56
  96. data/test/distributed_transactions_test.rb +0 -30
  97. data/test/encoding_test.rb +0 -14
  98. data/test/error_replies_test.rb +0 -57
  99. data/test/fork_safety_test.rb +0 -60
  100. data/test/helper.rb +0 -344
  101. data/test/helper_test.rb +0 -22
  102. data/test/internals_test.rb +0 -395
  103. data/test/lint/blocking_commands.rb +0 -174
  104. data/test/lint/hashes.rb +0 -203
  105. data/test/lint/hyper_log_log.rb +0 -74
  106. data/test/lint/lists.rb +0 -159
  107. data/test/lint/sets.rb +0 -282
  108. data/test/lint/sorted_sets.rb +0 -497
  109. data/test/lint/strings.rb +0 -348
  110. data/test/lint/value_types.rb +0 -130
  111. data/test/persistence_control_commands_test.rb +0 -24
  112. data/test/pipelining_commands_test.rb +0 -246
  113. data/test/publish_subscribe_test.rb +0 -280
  114. data/test/remote_server_control_commands_test.rb +0 -175
  115. data/test/scanning_test.rb +0 -407
  116. data/test/scripting_test.rb +0 -76
  117. data/test/sentinel_command_test.rb +0 -78
  118. data/test/sentinel_test.rb +0 -253
  119. data/test/sorting_test.rb +0 -57
  120. data/test/ssl_test.rb +0 -69
  121. data/test/support/cluster/orchestrator.rb +0 -199
  122. data/test/support/connection/hiredis.rb +0 -1
  123. data/test/support/connection/ruby.rb +0 -1
  124. data/test/support/connection/synchrony.rb +0 -17
  125. data/test/support/redis_mock.rb +0 -130
  126. data/test/support/ssl/gen_certs.sh +0 -31
  127. data/test/support/ssl/trusted-ca.crt +0 -25
  128. data/test/support/ssl/trusted-ca.key +0 -27
  129. data/test/support/ssl/trusted-cert.crt +0 -81
  130. data/test/support/ssl/trusted-cert.key +0 -28
  131. data/test/support/ssl/untrusted-ca.crt +0 -26
  132. data/test/support/ssl/untrusted-ca.key +0 -27
  133. data/test/support/ssl/untrusted-cert.crt +0 -82
  134. data/test/support/ssl/untrusted-cert.key +0 -28
  135. data/test/support/wire/synchrony.rb +0 -24
  136. data/test/support/wire/thread.rb +0 -5
  137. data/test/synchrony_driver.rb +0 -85
  138. data/test/test.conf.erb +0 -9
  139. data/test/thread_safety_test.rb +0 -60
  140. data/test/transactions_test.rb +0 -272
  141. data/test/unknown_commands_test.rb +0 -12
  142. data/test/url_param_test.rb +0 -136
@@ -1,497 +0,0 @@
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
- r.del "foo"
13
-
14
- target_version "3.0.2" do
15
- # XX option
16
- assert_equal 0, r.zcard("foo")
17
- assert_equal false, r.zadd("foo", 1, "s1", :xx => true)
18
- r.zadd("foo", 1, "s1")
19
- assert_equal false, r.zadd("foo", 2, "s1", :xx => true)
20
- assert_equal 2, r.zscore("foo", "s1")
21
- r.del "foo"
22
-
23
- # NX option
24
- assert_equal 0, r.zcard("foo")
25
- assert_equal true, r.zadd("foo", 1, "s1", :nx => true)
26
- assert_equal false, r.zadd("foo", 2, "s1", :nx => true)
27
- assert_equal 1, r.zscore("foo", "s1")
28
- assert_equal 1, r.zcard("foo")
29
- r.del "foo"
30
-
31
- # CH option
32
- assert_equal 0, r.zcard("foo")
33
- assert_equal true, r.zadd("foo", 1, "s1", :ch => true)
34
- assert_equal false, r.zadd("foo", 1, "s1", :ch => true)
35
- assert_equal true, r.zadd("foo", 2, "s1", :ch => true)
36
- assert_equal 1, r.zcard("foo")
37
- r.del "foo"
38
-
39
- # INCR option
40
- assert_equal 1.0, r.zadd("foo", 1, "s1", :incr => true)
41
- assert_equal 11.0, r.zadd("foo", 10, "s1", :incr => true)
42
- assert_equal(-Infinity, r.zadd("bar", "-inf", "s1", :incr => true))
43
- assert_equal(+Infinity, r.zadd("bar", "+inf", "s2", :incr => true))
44
- r.del 'foo'
45
- r.del 'bar'
46
-
47
- # Incompatible options combination
48
- assert_raise(Redis::CommandError) { r.zadd("foo", 1, "s1", :xx => true, :nx => true) }
49
- end
50
- end
51
-
52
- def test_variadic_zadd
53
- target_version "2.3.9" do # 2.4-rc6
54
- # Non-nested array with pairs
55
- assert_equal 0, r.zcard("foo")
56
- assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"])
57
- assert_equal 1, r.zadd("foo", [4, "s1", 5, "s2", 6, "s3"])
58
- assert_equal 3, r.zcard("foo")
59
- r.del "foo"
60
-
61
- # Nested array with pairs
62
- assert_equal 0, r.zcard("foo")
63
- assert_equal 2, r.zadd("foo", [[1, "s1"], [2, "s2"]])
64
- assert_equal 1, r.zadd("foo", [[4, "s1"], [5, "s2"], [6, "s3"]])
65
- assert_equal 3, r.zcard("foo")
66
- r.del "foo"
67
-
68
- # Wrong number of arguments
69
- assert_raise(Redis::CommandError) { r.zadd("foo", ["bar"]) }
70
- assert_raise(Redis::CommandError) { r.zadd("foo", ["bar", "qux", "zap"]) }
71
- end
72
-
73
- target_version "3.0.2" do
74
- # XX option
75
- assert_equal 0, r.zcard("foo")
76
- assert_equal 0, r.zadd("foo", [1, "s1", 2, "s2"], :xx => true)
77
- r.zadd("foo", [1, "s1", 2, "s2"])
78
- assert_equal 0, r.zadd("foo", [2, "s1", 3, "s2", 4, "s3"], :xx => true)
79
- assert_equal 2, r.zscore("foo", "s1")
80
- assert_equal 3, r.zscore("foo", "s2")
81
- assert_equal nil, r.zscore("foo", "s3")
82
- assert_equal 2, r.zcard("foo")
83
- r.del "foo"
84
-
85
- # NX option
86
- assert_equal 0, r.zcard("foo")
87
- assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"], :nx => true)
88
- assert_equal 1, r.zadd("foo", [2, "s1", 3, "s2", 4, "s3"], :nx => true)
89
- assert_equal 1, r.zscore("foo", "s1")
90
- assert_equal 2, r.zscore("foo", "s2")
91
- assert_equal 4, r.zscore("foo", "s3")
92
- assert_equal 3, r.zcard("foo")
93
- r.del "foo"
94
-
95
- # CH option
96
- assert_equal 0, r.zcard("foo")
97
- assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"], :ch => true)
98
- assert_equal 2, r.zadd("foo", [1, "s1", 3, "s2", 4, "s3"], :ch => true)
99
- assert_equal 3, r.zcard("foo")
100
- r.del "foo"
101
-
102
- # INCR option
103
- assert_equal 1.0, r.zadd("foo", [1, "s1"], :incr => true)
104
- assert_equal 11.0, r.zadd("foo", [10, "s1"], :incr => true)
105
- assert_equal(-Infinity, r.zadd("bar", ["-inf", "s1"], :incr => true))
106
- assert_equal(+Infinity, r.zadd("bar", ["+inf", "s2"], :incr => true))
107
- assert_raise(Redis::CommandError) { r.zadd("foo", [1, "s1", 2, "s2"], :incr => true) }
108
- r.del 'foo'
109
- r.del 'bar'
110
-
111
- # Incompatible options combination
112
- assert_raise(Redis::CommandError) { r.zadd("foo", [1, "s1"], :xx => true, :nx => true) }
113
- end
114
- end
115
-
116
- def test_zrem
117
- r.zadd("foo", 1, "s1")
118
- r.zadd("foo", 2, "s2")
119
-
120
- assert_equal 2, r.zcard("foo")
121
- assert_equal true, r.zrem("foo", "s1")
122
- assert_equal false, r.zrem("foo", "s1")
123
- assert_equal 1, r.zcard("foo")
124
- end
125
-
126
- def test_variadic_zrem
127
- target_version "2.3.9" do # 2.4-rc6
128
- r.zadd("foo", 1, "s1")
129
- r.zadd("foo", 2, "s2")
130
- r.zadd("foo", 3, "s3")
131
-
132
- assert_equal 3, r.zcard("foo")
133
- assert_equal 1, r.zrem("foo", ["s1", "aaa"])
134
- assert_equal 0, r.zrem("foo", ["bbb", "ccc" "ddd"])
135
- assert_equal 1, r.zrem("foo", ["eee", "s3"])
136
- assert_equal 1, r.zcard("foo")
137
- end
138
- end
139
-
140
- def test_zincrby
141
- rv = r.zincrby "foo", 1, "s1"
142
- assert_equal 1.0, rv
143
-
144
- rv = r.zincrby "foo", 10, "s1"
145
- assert_equal 11.0, rv
146
-
147
- rv = r.zincrby "bar", "-inf", "s1"
148
- assert_equal(-Infinity, rv)
149
-
150
- rv = r.zincrby "bar", "+inf", "s2"
151
- assert_equal(+Infinity, rv)
152
- end
153
-
154
- def test_zrank
155
- r.zadd "foo", 1, "s1"
156
- r.zadd "foo", 2, "s2"
157
- r.zadd "foo", 3, "s3"
158
-
159
- assert_equal 2, r.zrank("foo", "s3")
160
- end
161
-
162
- def test_zrevrank
163
- r.zadd "foo", 1, "s1"
164
- r.zadd "foo", 2, "s2"
165
- r.zadd "foo", 3, "s3"
166
-
167
- assert_equal 0, r.zrevrank("foo", "s3")
168
- end
169
-
170
- def test_zrange
171
- r.zadd "foo", 1, "s1"
172
- r.zadd "foo", 2, "s2"
173
- r.zadd "foo", 3, "s3"
174
-
175
- assert_equal ["s1", "s2"], r.zrange("foo", 0, 1)
176
- assert_equal [["s1", 1.0], ["s2", 2.0]], r.zrange("foo", 0, 1, :with_scores => true)
177
- assert_equal [["s1", 1.0], ["s2", 2.0]], r.zrange("foo", 0, 1, :withscores => true)
178
-
179
- r.zadd "bar", "-inf", "s1"
180
- r.zadd "bar", "+inf", "s2"
181
- assert_equal [["s1", -Infinity], ["s2", +Infinity]], r.zrange("bar", 0, 1, :with_scores => true)
182
- assert_equal [["s1", -Infinity], ["s2", +Infinity]], r.zrange("bar", 0, 1, :withscores => true)
183
- end
184
-
185
- def test_zrevrange
186
- r.zadd "foo", 1, "s1"
187
- r.zadd "foo", 2, "s2"
188
- r.zadd "foo", 3, "s3"
189
-
190
- assert_equal ["s3", "s2"], r.zrevrange("foo", 0, 1)
191
- assert_equal [["s3", 3.0], ["s2", 2.0]], r.zrevrange("foo", 0, 1, :with_scores => true)
192
- assert_equal [["s3", 3.0], ["s2", 2.0]], r.zrevrange("foo", 0, 1, :withscores => true)
193
-
194
- r.zadd "bar", "-inf", "s1"
195
- r.zadd "bar", "+inf", "s2"
196
- assert_equal [["s2", +Infinity], ["s1", -Infinity]], r.zrevrange("bar", 0, 1, :with_scores => true)
197
- assert_equal [["s2", +Infinity], ["s1", -Infinity]], r.zrevrange("bar", 0, 1, :withscores => true)
198
- end
199
-
200
- def test_zrangebyscore
201
- r.zadd "foo", 1, "s1"
202
- r.zadd "foo", 2, "s2"
203
- r.zadd "foo", 3, "s3"
204
-
205
- assert_equal ["s2", "s3"], r.zrangebyscore("foo", 2, 3)
206
- end
207
-
208
- def test_zrevrangebyscore
209
- r.zadd "foo", 1, "s1"
210
- r.zadd "foo", 2, "s2"
211
- r.zadd "foo", 3, "s3"
212
-
213
- assert_equal ["s3", "s2"], r.zrevrangebyscore("foo", 3, 2)
214
- end
215
-
216
- def test_zrangebyscore_with_limit
217
- r.zadd "foo", 1, "s1"
218
- r.zadd "foo", 2, "s2"
219
- r.zadd "foo", 3, "s3"
220
- r.zadd "foo", 4, "s4"
221
-
222
- assert_equal ["s2"], r.zrangebyscore("foo", 2, 4, :limit => [0, 1])
223
- assert_equal ["s3"], r.zrangebyscore("foo", 2, 4, :limit => [1, 1])
224
- assert_equal ["s3", "s4"], r.zrangebyscore("foo", 2, 4, :limit => [1, 2])
225
- end
226
-
227
- def test_zrevrangebyscore_with_limit
228
- r.zadd "foo", 1, "s1"
229
- r.zadd "foo", 2, "s2"
230
- r.zadd "foo", 3, "s3"
231
- r.zadd "foo", 4, "s4"
232
-
233
- assert_equal ["s4"], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1])
234
- assert_equal ["s3"], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1])
235
- assert_equal ["s3", "s2"], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 2])
236
- end
237
-
238
- def test_zrangebyscore_with_withscores
239
- r.zadd "foo", 1, "s1"
240
- r.zadd "foo", 2, "s2"
241
- r.zadd "foo", 3, "s3"
242
- r.zadd "foo", 4, "s4"
243
-
244
- assert_equal [["s2", 2.0]], r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :with_scores => true)
245
- assert_equal [["s3", 3.0]], r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :with_scores => true)
246
- assert_equal [["s2", 2.0]], r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :withscores => true)
247
- assert_equal [["s3", 3.0]], r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :withscores => true)
248
-
249
- r.zadd "bar", "-inf", "s1"
250
- r.zadd "bar", "+inf", "s2"
251
- assert_equal [["s1", -Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [0, 1], :with_scores => true)
252
- assert_equal [["s2", +Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [1, 1], :with_scores => true)
253
- assert_equal [["s1", -Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [0, 1], :withscores => true)
254
- assert_equal [["s2", +Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [1, 1], :withscores => true)
255
- end
256
-
257
- def test_zrevrangebyscore_with_withscores
258
- r.zadd "foo", 1, "s1"
259
- r.zadd "foo", 2, "s2"
260
- r.zadd "foo", 3, "s3"
261
- r.zadd "foo", 4, "s4"
262
-
263
- assert_equal [["s4", 4.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :with_scores => true)
264
- assert_equal [["s3", 3.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :with_scores => true)
265
- assert_equal [["s4", 4.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :withscores => true)
266
- assert_equal [["s3", 3.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :withscores => true)
267
-
268
- r.zadd "bar", "-inf", "s1"
269
- r.zadd "bar", "+inf", "s2"
270
- assert_equal [["s2", +Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [0, 1], :with_scores => true)
271
- assert_equal [["s1", -Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [1, 1], :with_scores => true)
272
- assert_equal [["s2", +Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [0, 1], :withscores => true)
273
- assert_equal [["s1", -Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [1, 1], :withscores => true)
274
- end
275
-
276
- def test_zcard
277
- assert_equal 0, r.zcard("foo")
278
-
279
- r.zadd "foo", 1, "s1"
280
-
281
- assert_equal 1, r.zcard("foo")
282
- end
283
-
284
- def test_zscore
285
- r.zadd "foo", 1, "s1"
286
-
287
- assert_equal 1.0, r.zscore("foo", "s1")
288
-
289
- assert_equal nil, r.zscore("foo", "s2")
290
- assert_equal nil, r.zscore("bar", "s1")
291
-
292
- r.zadd "bar", "-inf", "s1"
293
- r.zadd "bar", "+inf", "s2"
294
- assert_equal(-Infinity, r.zscore("bar", "s1"))
295
- assert_equal(+Infinity, r.zscore("bar", "s2"))
296
- end
297
-
298
- def test_zremrangebyrank
299
- r.zadd "foo", 10, "s1"
300
- r.zadd "foo", 20, "s2"
301
- r.zadd "foo", 30, "s3"
302
- r.zadd "foo", 40, "s4"
303
-
304
- assert_equal 3, r.zremrangebyrank("foo", 1, 3)
305
- assert_equal ["s1"], r.zrange("foo", 0, -1)
306
- end
307
-
308
- def test_zremrangebyscore
309
- r.zadd "foo", 1, "s1"
310
- r.zadd "foo", 2, "s2"
311
- r.zadd "foo", 3, "s3"
312
- r.zadd "foo", 4, "s4"
313
-
314
- assert_equal 3, r.zremrangebyscore("foo", 2, 4)
315
- assert_equal ["s1"], r.zrange("foo", 0, -1)
316
- end
317
-
318
- def test_zpopmax
319
- target_version('4.9.0') do
320
- r.zadd('foo', %w[0 a 1 b 2 c])
321
- assert_equal %w[c 2], r.zpopmax('foo')
322
- end
323
- end
324
-
325
- def test_zpopmin
326
- target_version('4.9.0') do
327
- r.zadd('foo', %w[0 a 1 b 2 c])
328
- assert_equal %w[a 0], r.zpopmin('foo')
329
- end
330
- end
331
-
332
- def test_zremrangebylex
333
- r.zadd('foo', %w[0 a 0 b 0 c 0 d 0 e 0 f 0 g])
334
- assert_equal 5, r.zremrangebylex('foo', '(b', '[g')
335
- end
336
-
337
- def test_zlexcount
338
- target_version '2.8.9' do
339
- r.zadd 'foo', 0, 'aaren'
340
- r.zadd 'foo', 0, 'abagael'
341
- r.zadd 'foo', 0, 'abby'
342
- r.zadd 'foo', 0, 'abbygail'
343
-
344
- assert_equal 4, r.zlexcount('foo', '[a', "[a\xff")
345
- assert_equal 4, r.zlexcount('foo', '[aa', "[ab\xff")
346
- assert_equal 3, r.zlexcount('foo', '(aaren', "[ab\xff")
347
- assert_equal 2, r.zlexcount('foo', '[aba', '(abbygail')
348
- assert_equal 1, r.zlexcount('foo', '(aaren', '(abby')
349
- end
350
- end
351
-
352
- def test_zrangebylex
353
- target_version '2.8.9' do
354
- r.zadd 'foo', 0, 'aaren'
355
- r.zadd 'foo', 0, 'abagael'
356
- r.zadd 'foo', 0, 'abby'
357
- r.zadd 'foo', 0, 'abbygail'
358
-
359
- assert_equal %w[aaren abagael abby abbygail], r.zrangebylex('foo', '[a', "[a\xff")
360
- assert_equal %w[aaren abagael], r.zrangebylex('foo', '[a', "[a\xff", limit: [0, 2])
361
- assert_equal %w[abby abbygail], r.zrangebylex('foo', '(abb', "(abb\xff")
362
- assert_equal %w[abbygail], r.zrangebylex('foo', '(abby', "(abby\xff")
363
- end
364
- end
365
-
366
- def test_zrevrangebylex
367
- target_version '2.9.9' do
368
- r.zadd 'foo', 0, 'aaren'
369
- r.zadd 'foo', 0, 'abagael'
370
- r.zadd 'foo', 0, 'abby'
371
- r.zadd 'foo', 0, 'abbygail'
372
-
373
- assert_equal %w[abbygail abby abagael aaren], r.zrevrangebylex('foo', "[a\xff", '[a')
374
- assert_equal %w[abbygail abby], r.zrevrangebylex('foo', "[a\xff", '[a', limit: [0, 2])
375
- assert_equal %w[abbygail abby], r.zrevrangebylex('foo', "(abb\xff", '(abb')
376
- assert_equal %w[abbygail], r.zrevrangebylex('foo', "(abby\xff", '(abby')
377
- end
378
- end
379
-
380
- def test_zcount
381
- r.zadd 'foo', 1, 's1'
382
- r.zadd 'foo', 2, 's2'
383
- r.zadd 'foo', 3, 's3'
384
-
385
- assert_equal 2, r.zcount('foo', 2, 3)
386
- end
387
-
388
- def test_zunionstore
389
- r.zadd 'foo', 1, 's1'
390
- r.zadd 'bar', 2, 's2'
391
- r.zadd 'foo', 3, 's3'
392
- r.zadd 'bar', 4, 's4'
393
-
394
- assert_equal 4, r.zunionstore('foobar', %w[foo bar])
395
- assert_equal %w[s1 s2 s3 s4], r.zrange('foobar', 0, -1)
396
- end
397
-
398
- def test_zunionstore_with_weights
399
- r.zadd 'foo', 1, 's1'
400
- r.zadd 'foo', 3, 's3'
401
- r.zadd 'bar', 20, 's2'
402
- r.zadd 'bar', 40, 's4'
403
-
404
- assert_equal 4, r.zunionstore('foobar', %w[foo bar])
405
- assert_equal %w[s1 s3 s2 s4], r.zrange('foobar', 0, -1)
406
-
407
- assert_equal 4, r.zunionstore('foobar', %w[foo bar], weights: [10, 1])
408
- assert_equal %w[s1 s2 s3 s4], r.zrange('foobar', 0, -1)
409
- end
410
-
411
- def test_zunionstore_with_aggregate
412
- r.zadd 'foo', 1, 's1'
413
- r.zadd 'foo', 2, 's2'
414
- r.zadd 'bar', 4, 's2'
415
- r.zadd 'bar', 3, 's3'
416
-
417
- assert_equal 3, r.zunionstore('foobar', %w[foo bar])
418
- assert_equal %w[s1 s3 s2], r.zrange('foobar', 0, -1)
419
-
420
- assert_equal 3, r.zunionstore('foobar', %w[foo bar], aggregate: :min)
421
- assert_equal %w[s1 s2 s3], r.zrange('foobar', 0, -1)
422
-
423
- assert_equal 3, r.zunionstore('foobar', %w[foo bar], aggregate: :max)
424
- assert_equal %w[s1 s3 s2], r.zrange('foobar', 0, -1)
425
- end
426
-
427
- def test_zunionstore_expand
428
- r.zadd('{1}foo', %w[0 a 1 b 2 c])
429
- r.zadd('{1}bar', %w[0 c 1 d 2 e])
430
- assert_equal 5, r.zunionstore('{1}baz', %w[{1}foo {1}bar])
431
- end
432
-
433
- def test_zinterstore
434
- r.zadd 'foo', 1, 's1'
435
- r.zadd 'bar', 2, 's1'
436
- r.zadd 'foo', 3, 's3'
437
- r.zadd 'bar', 4, 's4'
438
-
439
- assert_equal 1, r.zinterstore('foobar', %w[foo bar])
440
- assert_equal ['s1'], r.zrange('foobar', 0, -1)
441
- end
442
-
443
- def test_zinterstore_with_weights
444
- r.zadd 'foo', 1, 's1'
445
- r.zadd 'foo', 2, 's2'
446
- r.zadd 'foo', 3, 's3'
447
- r.zadd 'bar', 20, 's2'
448
- r.zadd 'bar', 30, 's3'
449
- r.zadd 'bar', 40, 's4'
450
-
451
- assert_equal 2, r.zinterstore('foobar', %w[foo bar])
452
- assert_equal %w[s2 s3], r.zrange('foobar', 0, -1)
453
-
454
- assert_equal 2, r.zinterstore('foobar', %w[foo bar], weights: [10, 1])
455
- assert_equal %w[s2 s3], r.zrange('foobar', 0, -1)
456
-
457
- assert_equal 40.0, r.zscore('foobar', 's2')
458
- assert_equal 60.0, r.zscore('foobar', 's3')
459
- end
460
-
461
- def test_zinterstore_with_aggregate
462
- r.zadd 'foo', 1, 's1'
463
- r.zadd 'foo', 2, 's2'
464
- r.zadd 'foo', 3, 's3'
465
- r.zadd 'bar', 20, 's2'
466
- r.zadd 'bar', 30, 's3'
467
- r.zadd 'bar', 40, 's4'
468
-
469
- assert_equal 2, r.zinterstore('foobar', %w[foo bar])
470
- assert_equal %w[s2 s3], r.zrange('foobar', 0, -1)
471
- assert_equal 22.0, r.zscore('foobar', 's2')
472
- assert_equal 33.0, r.zscore('foobar', 's3')
473
-
474
- assert_equal 2, r.zinterstore('foobar', %w[foo bar], aggregate: :min)
475
- assert_equal %w[s2 s3], r.zrange('foobar', 0, -1)
476
- assert_equal 2.0, r.zscore('foobar', 's2')
477
- assert_equal 3.0, r.zscore('foobar', 's3')
478
-
479
- assert_equal 2, r.zinterstore('foobar', %w[foo bar], aggregate: :max)
480
- assert_equal %w[s2 s3], r.zrange('foobar', 0, -1)
481
- assert_equal 20.0, r.zscore('foobar', 's2')
482
- assert_equal 30.0, r.zscore('foobar', 's3')
483
- end
484
-
485
- def test_zinterstore_expand
486
- r.zadd '{1}foo', %w[0 s1 1 s2 2 s3]
487
- r.zadd '{1}bar', %w[0 s3 1 s4 2 s5]
488
- assert_equal 1, r.zinterstore('{1}baz', %w[{1}foo {1}bar], weights: [2.0, 3.0])
489
- end
490
-
491
- def test_zscan
492
- r.zadd('foo', %w[0 a 1 b 2 c])
493
- expected = ['0', [['a', 0.0], ['b', 1.0], ['c', 2.0]]]
494
- assert_equal expected, r.zscan('foo', 0)
495
- end
496
- end
497
- end