redis 3.3.5 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -2
  3. data/README.md +77 -76
  4. data/lib/redis.rb +779 -63
  5. data/lib/redis/client.rb +41 -20
  6. data/lib/redis/cluster.rb +286 -0
  7. data/lib/redis/cluster/command.rb +81 -0
  8. data/lib/redis/cluster/command_loader.rb +34 -0
  9. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  10. data/lib/redis/cluster/node.rb +104 -0
  11. data/lib/redis/cluster/node_key.rb +35 -0
  12. data/lib/redis/cluster/node_loader.rb +37 -0
  13. data/lib/redis/cluster/option.rb +77 -0
  14. data/lib/redis/cluster/slot.rb +69 -0
  15. data/lib/redis/cluster/slot_loader.rb +49 -0
  16. data/lib/redis/connection.rb +2 -2
  17. data/lib/redis/connection/command_helper.rb +2 -8
  18. data/lib/redis/connection/hiredis.rb +2 -2
  19. data/lib/redis/connection/ruby.rb +13 -30
  20. data/lib/redis/connection/synchrony.rb +12 -4
  21. data/lib/redis/distributed.rb +32 -12
  22. data/lib/redis/errors.rb +46 -0
  23. data/lib/redis/hash_ring.rb +20 -64
  24. data/lib/redis/pipeline.rb +9 -7
  25. data/lib/redis/version.rb +1 -1
  26. metadata +53 -196
  27. data/.gitignore +0 -16
  28. data/.travis.yml +0 -89
  29. data/.travis/Gemfile +0 -11
  30. data/.yardopts +0 -3
  31. data/Gemfile +0 -4
  32. data/Rakefile +0 -87
  33. data/benchmarking/logging.rb +0 -71
  34. data/benchmarking/pipeline.rb +0 -51
  35. data/benchmarking/speed.rb +0 -21
  36. data/benchmarking/suite.rb +0 -24
  37. data/benchmarking/worker.rb +0 -71
  38. data/examples/basic.rb +0 -15
  39. data/examples/consistency.rb +0 -114
  40. data/examples/dist_redis.rb +0 -43
  41. data/examples/incr-decr.rb +0 -17
  42. data/examples/list.rb +0 -26
  43. data/examples/pubsub.rb +0 -37
  44. data/examples/sentinel.rb +0 -41
  45. data/examples/sentinel/start +0 -49
  46. data/examples/sets.rb +0 -36
  47. data/examples/unicorn/config.ru +0 -3
  48. data/examples/unicorn/unicorn.rb +0 -20
  49. data/redis.gemspec +0 -44
  50. data/test/bitpos_test.rb +0 -69
  51. data/test/blocking_commands_test.rb +0 -42
  52. data/test/client_test.rb +0 -59
  53. data/test/command_map_test.rb +0 -30
  54. data/test/commands_on_hashes_test.rb +0 -21
  55. data/test/commands_on_hyper_log_log_test.rb +0 -21
  56. data/test/commands_on_lists_test.rb +0 -20
  57. data/test/commands_on_sets_test.rb +0 -77
  58. data/test/commands_on_sorted_sets_test.rb +0 -137
  59. data/test/commands_on_strings_test.rb +0 -101
  60. data/test/commands_on_value_types_test.rb +0 -133
  61. data/test/connection_handling_test.rb +0 -277
  62. data/test/connection_test.rb +0 -57
  63. data/test/distributed_blocking_commands_test.rb +0 -46
  64. data/test/distributed_commands_on_hashes_test.rb +0 -10
  65. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  66. data/test/distributed_commands_on_lists_test.rb +0 -22
  67. data/test/distributed_commands_on_sets_test.rb +0 -83
  68. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  69. data/test/distributed_commands_on_strings_test.rb +0 -59
  70. data/test/distributed_commands_on_value_types_test.rb +0 -95
  71. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  72. data/test/distributed_connection_handling_test.rb +0 -23
  73. data/test/distributed_internals_test.rb +0 -79
  74. data/test/distributed_key_tags_test.rb +0 -52
  75. data/test/distributed_persistence_control_commands_test.rb +0 -26
  76. data/test/distributed_publish_subscribe_test.rb +0 -92
  77. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  78. data/test/distributed_scripting_test.rb +0 -102
  79. data/test/distributed_sorting_test.rb +0 -20
  80. data/test/distributed_test.rb +0 -58
  81. data/test/distributed_transactions_test.rb +0 -32
  82. data/test/encoding_test.rb +0 -18
  83. data/test/error_replies_test.rb +0 -59
  84. data/test/fork_safety_test.rb +0 -65
  85. data/test/helper.rb +0 -232
  86. data/test/helper_test.rb +0 -24
  87. data/test/internals_test.rb +0 -417
  88. data/test/lint/blocking_commands.rb +0 -150
  89. data/test/lint/hashes.rb +0 -162
  90. data/test/lint/hyper_log_log.rb +0 -60
  91. data/test/lint/lists.rb +0 -143
  92. data/test/lint/sets.rb +0 -140
  93. data/test/lint/sorted_sets.rb +0 -316
  94. data/test/lint/strings.rb +0 -260
  95. data/test/lint/value_types.rb +0 -122
  96. data/test/persistence_control_commands_test.rb +0 -26
  97. data/test/pipelining_commands_test.rb +0 -242
  98. data/test/publish_subscribe_test.rb +0 -282
  99. data/test/remote_server_control_commands_test.rb +0 -118
  100. data/test/scanning_test.rb +0 -413
  101. data/test/scripting_test.rb +0 -78
  102. data/test/sentinel_command_test.rb +0 -80
  103. data/test/sentinel_test.rb +0 -255
  104. data/test/sorting_test.rb +0 -59
  105. data/test/ssl_test.rb +0 -73
  106. data/test/support/connection/hiredis.rb +0 -1
  107. data/test/support/connection/ruby.rb +0 -1
  108. data/test/support/connection/synchrony.rb +0 -17
  109. data/test/support/redis_mock.rb +0 -130
  110. data/test/support/ssl/gen_certs.sh +0 -31
  111. data/test/support/ssl/trusted-ca.crt +0 -25
  112. data/test/support/ssl/trusted-ca.key +0 -27
  113. data/test/support/ssl/trusted-cert.crt +0 -81
  114. data/test/support/ssl/trusted-cert.key +0 -28
  115. data/test/support/ssl/untrusted-ca.crt +0 -26
  116. data/test/support/ssl/untrusted-ca.key +0 -27
  117. data/test/support/ssl/untrusted-cert.crt +0 -82
  118. data/test/support/ssl/untrusted-cert.key +0 -28
  119. data/test/support/wire/synchrony.rb +0 -24
  120. data/test/support/wire/thread.rb +0 -5
  121. data/test/synchrony_driver.rb +0 -88
  122. data/test/test.conf.erb +0 -9
  123. data/test/thread_safety_test.rb +0 -62
  124. data/test/transactions_test.rb +0 -264
  125. data/test/unknown_commands_test.rb +0 -14
  126. data/test/url_param_test.rb +0 -138
@@ -1,140 +0,0 @@
1
- module Lint
2
-
3
- module Sets
4
-
5
- def test_sadd
6
- assert_equal true, r.sadd("foo", "s1")
7
- assert_equal true, r.sadd("foo", "s2")
8
- assert_equal false, r.sadd("foo", "s1")
9
-
10
- assert_equal ["s1", "s2"], r.smembers("foo").sort
11
- end
12
-
13
- def test_variadic_sadd
14
- target_version "2.3.9" do # 2.4-rc6
15
- assert_equal 2, r.sadd("foo", ["s1", "s2"])
16
- assert_equal 1, r.sadd("foo", ["s1", "s2", "s3"])
17
-
18
- assert_equal ["s1", "s2", "s3"], r.smembers("foo").sort
19
- end
20
- end
21
-
22
- def test_srem
23
- r.sadd("foo", "s1")
24
- r.sadd("foo", "s2")
25
-
26
- assert_equal true, r.srem("foo", "s1")
27
- assert_equal false, r.srem("foo", "s3")
28
-
29
- assert_equal ["s2"], r.smembers("foo")
30
- end
31
-
32
- def test_variadic_srem
33
- target_version "2.3.9" do # 2.4-rc6
34
- r.sadd("foo", "s1")
35
- r.sadd("foo", "s2")
36
- r.sadd("foo", "s3")
37
-
38
- assert_equal 1, r.srem("foo", ["s1", "aaa"])
39
- assert_equal 0, r.srem("foo", ["bbb", "ccc" "ddd"])
40
- assert_equal 1, r.srem("foo", ["eee", "s3"])
41
-
42
- assert_equal ["s2"], r.smembers("foo")
43
- end
44
- end
45
-
46
- def test_spop
47
- r.sadd "foo", "s1"
48
- r.sadd "foo", "s2"
49
-
50
- assert ["s1", "s2"].include?(r.spop("foo"))
51
- assert ["s1", "s2"].include?(r.spop("foo"))
52
- assert_equal nil, r.spop("foo")
53
- end
54
-
55
- def test_spop_with_positive_count
56
- target_version "3.2.0" do
57
- r.sadd "foo", "s1"
58
- r.sadd "foo", "s2"
59
- r.sadd "foo", "s3"
60
- r.sadd "foo", "s4"
61
-
62
- pops = r.spop("foo", 3)
63
-
64
- assert !(["s1", "s2", "s3", "s4"] & pops).empty?
65
- assert_equal 3, pops.size
66
- assert_equal 1, r.scard("foo")
67
- end
68
- end
69
-
70
- def test_scard
71
- assert_equal 0, r.scard("foo")
72
-
73
- r.sadd "foo", "s1"
74
-
75
- assert_equal 1, r.scard("foo")
76
-
77
- r.sadd "foo", "s2"
78
-
79
- assert_equal 2, r.scard("foo")
80
- end
81
-
82
- def test_sismember
83
- assert_equal false, r.sismember("foo", "s1")
84
-
85
- r.sadd "foo", "s1"
86
-
87
- assert_equal true, r.sismember("foo", "s1")
88
- assert_equal false, r.sismember("foo", "s2")
89
- end
90
-
91
- def test_smembers
92
- assert_equal [], r.smembers("foo")
93
-
94
- r.sadd "foo", "s1"
95
- r.sadd "foo", "s2"
96
-
97
- assert_equal ["s1", "s2"], r.smembers("foo").sort
98
- end
99
-
100
- def test_srandmember
101
- r.sadd "foo", "s1"
102
- r.sadd "foo", "s2"
103
-
104
- 4.times do
105
- assert ["s1", "s2"].include?(r.srandmember("foo"))
106
- end
107
-
108
- assert_equal 2, r.scard("foo")
109
- end
110
-
111
- def test_srandmember_with_positive_count
112
- r.sadd "foo", "s1"
113
- r.sadd "foo", "s2"
114
- r.sadd "foo", "s3"
115
- r.sadd "foo", "s4"
116
-
117
- 4.times do
118
- assert !(["s1", "s2", "s3", "s4"] & r.srandmember("foo", 3)).empty?
119
-
120
- assert_equal 3, r.srandmember("foo", 3).size
121
- end
122
-
123
- assert_equal 4, r.scard("foo")
124
- end
125
-
126
- def test_srandmember_with_negative_count
127
- r.sadd "foo", "s1"
128
- r.sadd "foo", "s2"
129
- r.sadd "foo", "s3"
130
- r.sadd "foo", "s4"
131
-
132
- 4.times do
133
- assert !(["s1", "s2", "s3", "s4"] & r.srandmember("foo", -6)).empty?
134
- assert_equal 6, r.srandmember("foo", -6).size
135
- end
136
-
137
- assert_equal 4, r.scard("foo")
138
- end
139
- end
140
- end
@@ -1,316 +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", "bar"
45
-
46
- # Incompatible options combination
47
- assert_raise(Redis::CommandError) { r.zadd("foo", 1, "s1", :xx => true, :nx => true) }
48
- end
49
- end
50
-
51
- def test_variadic_zadd
52
- target_version "2.3.9" do # 2.4-rc6
53
- # Non-nested array with pairs
54
- assert_equal 0, r.zcard("foo")
55
- assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"])
56
- assert_equal 1, r.zadd("foo", [4, "s1", 5, "s2", 6, "s3"])
57
- assert_equal 3, r.zcard("foo")
58
- r.del "foo"
59
-
60
- # Nested array with pairs
61
- assert_equal 0, r.zcard("foo")
62
- assert_equal 2, r.zadd("foo", [[1, "s1"], [2, "s2"]])
63
- assert_equal 1, r.zadd("foo", [[4, "s1"], [5, "s2"], [6, "s3"]])
64
- assert_equal 3, r.zcard("foo")
65
- r.del "foo"
66
-
67
- # Wrong number of arguments
68
- assert_raise(Redis::CommandError) { r.zadd("foo", ["bar"]) }
69
- assert_raise(Redis::CommandError) { r.zadd("foo", ["bar", "qux", "zap"]) }
70
- end
71
-
72
- target_version "3.0.2" do
73
- # XX option
74
- assert_equal 0, r.zcard("foo")
75
- assert_equal 0, r.zadd("foo", [1, "s1", 2, "s2"], :xx => true)
76
- r.zadd("foo", [1, "s1", 2, "s2"])
77
- assert_equal 0, r.zadd("foo", [2, "s1", 3, "s2", 4, "s3"], :xx => true)
78
- assert_equal 2, r.zscore("foo", "s1")
79
- assert_equal 3, r.zscore("foo", "s2")
80
- assert_equal nil, r.zscore("foo", "s3")
81
- assert_equal 2, r.zcard("foo")
82
- r.del "foo"
83
-
84
- # NX option
85
- assert_equal 0, r.zcard("foo")
86
- assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"], :nx => true)
87
- assert_equal 1, r.zadd("foo", [2, "s1", 3, "s2", 4, "s3"], :nx => true)
88
- assert_equal 1, r.zscore("foo", "s1")
89
- assert_equal 2, r.zscore("foo", "s2")
90
- assert_equal 4, r.zscore("foo", "s3")
91
- assert_equal 3, r.zcard("foo")
92
- r.del "foo"
93
-
94
- # CH option
95
- assert_equal 0, r.zcard("foo")
96
- assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"], :ch => true)
97
- assert_equal 2, r.zadd("foo", [1, "s1", 3, "s2", 4, "s3"], :ch => true)
98
- assert_equal 3, r.zcard("foo")
99
- r.del "foo"
100
-
101
- # INCR option
102
- assert_equal 1.0, r.zadd("foo", [1, "s1"], :incr => true)
103
- assert_equal 11.0, r.zadd("foo", [10, "s1"], :incr => true)
104
- assert_equal(-Infinity, r.zadd("bar", ["-inf", "s1"], :incr => true))
105
- assert_equal(+Infinity, r.zadd("bar", ["+inf", "s2"], :incr => true))
106
- assert_raise(Redis::CommandError) { r.zadd("foo", [1, "s1", 2, "s2"], :incr => true) }
107
- r.del "foo", "bar"
108
-
109
- # Incompatible options combination
110
- assert_raise(Redis::CommandError) { r.zadd("foo", [1, "s1"], :xx => true, :nx => true) }
111
- end
112
- end
113
-
114
- def test_zrem
115
- r.zadd("foo", 1, "s1")
116
- r.zadd("foo", 2, "s2")
117
-
118
- assert_equal 2, r.zcard("foo")
119
- assert_equal true, r.zrem("foo", "s1")
120
- assert_equal false, r.zrem("foo", "s1")
121
- assert_equal 1, r.zcard("foo")
122
- end
123
-
124
- def test_variadic_zrem
125
- target_version "2.3.9" do # 2.4-rc6
126
- r.zadd("foo", 1, "s1")
127
- r.zadd("foo", 2, "s2")
128
- r.zadd("foo", 3, "s3")
129
-
130
- assert_equal 3, r.zcard("foo")
131
- assert_equal 1, r.zrem("foo", ["s1", "aaa"])
132
- assert_equal 0, r.zrem("foo", ["bbb", "ccc" "ddd"])
133
- assert_equal 1, r.zrem("foo", ["eee", "s3"])
134
- assert_equal 1, r.zcard("foo")
135
- end
136
- end
137
-
138
- def test_zincrby
139
- rv = r.zincrby "foo", 1, "s1"
140
- assert_equal 1.0, rv
141
-
142
- rv = r.zincrby "foo", 10, "s1"
143
- assert_equal 11.0, rv
144
-
145
- rv = r.zincrby "bar", "-inf", "s1"
146
- assert_equal(-Infinity, rv)
147
-
148
- rv = r.zincrby "bar", "+inf", "s2"
149
- assert_equal(+Infinity, rv)
150
- end
151
-
152
- def test_zrank
153
- r.zadd "foo", 1, "s1"
154
- r.zadd "foo", 2, "s2"
155
- r.zadd "foo", 3, "s3"
156
-
157
- assert_equal 2, r.zrank("foo", "s3")
158
- end
159
-
160
- def test_zrevrank
161
- r.zadd "foo", 1, "s1"
162
- r.zadd "foo", 2, "s2"
163
- r.zadd "foo", 3, "s3"
164
-
165
- assert_equal 0, r.zrevrank("foo", "s3")
166
- end
167
-
168
- def test_zrange
169
- r.zadd "foo", 1, "s1"
170
- r.zadd "foo", 2, "s2"
171
- r.zadd "foo", 3, "s3"
172
-
173
- assert_equal ["s1", "s2"], r.zrange("foo", 0, 1)
174
- assert_equal [["s1", 1.0], ["s2", 2.0]], r.zrange("foo", 0, 1, :with_scores => true)
175
- assert_equal [["s1", 1.0], ["s2", 2.0]], r.zrange("foo", 0, 1, :withscores => true)
176
-
177
- r.zadd "bar", "-inf", "s1"
178
- r.zadd "bar", "+inf", "s2"
179
- assert_equal [["s1", -Infinity], ["s2", +Infinity]], r.zrange("bar", 0, 1, :with_scores => true)
180
- assert_equal [["s1", -Infinity], ["s2", +Infinity]], r.zrange("bar", 0, 1, :withscores => true)
181
- end
182
-
183
- def test_zrevrange
184
- r.zadd "foo", 1, "s1"
185
- r.zadd "foo", 2, "s2"
186
- r.zadd "foo", 3, "s3"
187
-
188
- assert_equal ["s3", "s2"], r.zrevrange("foo", 0, 1)
189
- assert_equal [["s3", 3.0], ["s2", 2.0]], r.zrevrange("foo", 0, 1, :with_scores => true)
190
- assert_equal [["s3", 3.0], ["s2", 2.0]], r.zrevrange("foo", 0, 1, :withscores => true)
191
-
192
- r.zadd "bar", "-inf", "s1"
193
- r.zadd "bar", "+inf", "s2"
194
- assert_equal [["s2", +Infinity], ["s1", -Infinity]], r.zrevrange("bar", 0, 1, :with_scores => true)
195
- assert_equal [["s2", +Infinity], ["s1", -Infinity]], r.zrevrange("bar", 0, 1, :withscores => true)
196
- end
197
-
198
- def test_zrangebyscore
199
- r.zadd "foo", 1, "s1"
200
- r.zadd "foo", 2, "s2"
201
- r.zadd "foo", 3, "s3"
202
-
203
- assert_equal ["s2", "s3"], r.zrangebyscore("foo", 2, 3)
204
- end
205
-
206
- def test_zrevrangebyscore
207
- r.zadd "foo", 1, "s1"
208
- r.zadd "foo", 2, "s2"
209
- r.zadd "foo", 3, "s3"
210
-
211
- assert_equal ["s3", "s2"], r.zrevrangebyscore("foo", 3, 2)
212
- end
213
-
214
- def test_zrangebyscore_with_limit
215
- r.zadd "foo", 1, "s1"
216
- r.zadd "foo", 2, "s2"
217
- r.zadd "foo", 3, "s3"
218
- r.zadd "foo", 4, "s4"
219
-
220
- assert_equal ["s2"], r.zrangebyscore("foo", 2, 4, :limit => [0, 1])
221
- assert_equal ["s3"], r.zrangebyscore("foo", 2, 4, :limit => [1, 1])
222
- assert_equal ["s3", "s4"], r.zrangebyscore("foo", 2, 4, :limit => [1, 2])
223
- end
224
-
225
- def test_zrevrangebyscore_with_limit
226
- r.zadd "foo", 1, "s1"
227
- r.zadd "foo", 2, "s2"
228
- r.zadd "foo", 3, "s3"
229
- r.zadd "foo", 4, "s4"
230
-
231
- assert_equal ["s4"], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1])
232
- assert_equal ["s3"], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1])
233
- assert_equal ["s3", "s2"], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 2])
234
- end
235
-
236
- def test_zrangebyscore_with_withscores
237
- r.zadd "foo", 1, "s1"
238
- r.zadd "foo", 2, "s2"
239
- r.zadd "foo", 3, "s3"
240
- r.zadd "foo", 4, "s4"
241
-
242
- assert_equal [["s2", 2.0]], r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :with_scores => true)
243
- assert_equal [["s3", 3.0]], r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :with_scores => true)
244
- assert_equal [["s2", 2.0]], r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :withscores => true)
245
- assert_equal [["s3", 3.0]], r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :withscores => true)
246
-
247
- r.zadd "bar", "-inf", "s1"
248
- r.zadd "bar", "+inf", "s2"
249
- assert_equal [["s1", -Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [0, 1], :with_scores => true)
250
- assert_equal [["s2", +Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [1, 1], :with_scores => true)
251
- assert_equal [["s1", -Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [0, 1], :withscores => true)
252
- assert_equal [["s2", +Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [1, 1], :withscores => true)
253
- end
254
-
255
- def test_zrevrangebyscore_with_withscores
256
- r.zadd "foo", 1, "s1"
257
- r.zadd "foo", 2, "s2"
258
- r.zadd "foo", 3, "s3"
259
- r.zadd "foo", 4, "s4"
260
-
261
- assert_equal [["s4", 4.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :with_scores => true)
262
- assert_equal [["s3", 3.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :with_scores => true)
263
- assert_equal [["s4", 4.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :withscores => true)
264
- assert_equal [["s3", 3.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :withscores => true)
265
-
266
- r.zadd "bar", "-inf", "s1"
267
- r.zadd "bar", "+inf", "s2"
268
- assert_equal [["s2", +Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [0, 1], :with_scores => true)
269
- assert_equal [["s1", -Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [1, 1], :with_scores => true)
270
- assert_equal [["s2", +Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [0, 1], :withscores => true)
271
- assert_equal [["s1", -Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [1, 1], :withscores => true)
272
- end
273
-
274
- def test_zcard
275
- assert_equal 0, r.zcard("foo")
276
-
277
- r.zadd "foo", 1, "s1"
278
-
279
- assert_equal 1, r.zcard("foo")
280
- end
281
-
282
- def test_zscore
283
- r.zadd "foo", 1, "s1"
284
-
285
- assert_equal 1.0, r.zscore("foo", "s1")
286
-
287
- assert_equal nil, r.zscore("foo", "s2")
288
- assert_equal nil, r.zscore("bar", "s1")
289
-
290
- r.zadd "bar", "-inf", "s1"
291
- r.zadd "bar", "+inf", "s2"
292
- assert_equal(-Infinity, r.zscore("bar", "s1"))
293
- assert_equal(+Infinity, r.zscore("bar", "s2"))
294
- end
295
-
296
- def test_zremrangebyrank
297
- r.zadd "foo", 10, "s1"
298
- r.zadd "foo", 20, "s2"
299
- r.zadd "foo", 30, "s3"
300
- r.zadd "foo", 40, "s4"
301
-
302
- assert_equal 3, r.zremrangebyrank("foo", 1, 3)
303
- assert_equal ["s1"], r.zrange("foo", 0, -1)
304
- end
305
-
306
- def test_zremrangebyscore
307
- r.zadd "foo", 1, "s1"
308
- r.zadd "foo", 2, "s2"
309
- r.zadd "foo", 3, "s3"
310
- r.zadd "foo", 4, "s4"
311
-
312
- assert_equal 3, r.zremrangebyscore("foo", 2, 4)
313
- assert_equal ["s1"], r.zrange("foo", 0, -1)
314
- end
315
- end
316
- end