redis 3.0.0.rc1 → 3.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.travis.yml +50 -0
  2. data/.travis/Gemfile +11 -0
  3. data/CHANGELOG.md +47 -19
  4. data/README.md +160 -149
  5. data/Rakefile +15 -50
  6. data/examples/pubsub.rb +1 -1
  7. data/examples/unicorn/config.ru +1 -1
  8. data/examples/unicorn/unicorn.rb +1 -1
  9. data/lib/redis.rb +790 -390
  10. data/lib/redis/client.rb +137 -49
  11. data/lib/redis/connection/hiredis.rb +26 -15
  12. data/lib/redis/connection/ruby.rb +170 -53
  13. data/lib/redis/connection/synchrony.rb +23 -35
  14. data/lib/redis/distributed.rb +92 -32
  15. data/lib/redis/errors.rb +4 -2
  16. data/lib/redis/pipeline.rb +17 -6
  17. data/lib/redis/version.rb +1 -1
  18. data/redis.gemspec +4 -6
  19. data/test/blocking_commands_test.rb +42 -0
  20. data/test/command_map_test.rb +18 -17
  21. data/test/commands_on_hashes_test.rb +13 -12
  22. data/test/commands_on_lists_test.rb +35 -45
  23. data/test/commands_on_sets_test.rb +55 -54
  24. data/test/commands_on_sorted_sets_test.rb +106 -105
  25. data/test/commands_on_strings_test.rb +64 -55
  26. data/test/commands_on_value_types_test.rb +66 -54
  27. data/test/connection_handling_test.rb +136 -151
  28. data/test/distributed_blocking_commands_test.rb +33 -40
  29. data/test/distributed_commands_on_hashes_test.rb +6 -7
  30. data/test/distributed_commands_on_lists_test.rb +13 -14
  31. data/test/distributed_commands_on_sets_test.rb +57 -58
  32. data/test/distributed_commands_on_sorted_sets_test.rb +11 -12
  33. data/test/distributed_commands_on_strings_test.rb +31 -32
  34. data/test/distributed_commands_on_value_types_test.rb +61 -46
  35. data/test/distributed_commands_requiring_clustering_test.rb +108 -108
  36. data/test/distributed_connection_handling_test.rb +14 -15
  37. data/test/distributed_internals_test.rb +7 -19
  38. data/test/distributed_key_tags_test.rb +36 -36
  39. data/test/distributed_persistence_control_commands_test.rb +17 -14
  40. data/test/distributed_publish_subscribe_test.rb +61 -69
  41. data/test/distributed_remote_server_control_commands_test.rb +39 -28
  42. data/test/distributed_sorting_test.rb +12 -13
  43. data/test/distributed_test.rb +40 -41
  44. data/test/distributed_transactions_test.rb +20 -21
  45. data/test/encoding_test.rb +12 -9
  46. data/test/error_replies_test.rb +42 -36
  47. data/test/helper.rb +118 -85
  48. data/test/helper_test.rb +20 -6
  49. data/test/internals_test.rb +167 -103
  50. data/test/lint/blocking_commands.rb +124 -0
  51. data/test/lint/hashes.rb +115 -93
  52. data/test/lint/lists.rb +86 -80
  53. data/test/lint/sets.rb +68 -62
  54. data/test/lint/sorted_sets.rb +200 -195
  55. data/test/lint/strings.rb +112 -94
  56. data/test/lint/value_types.rb +76 -55
  57. data/test/persistence_control_commands_test.rb +17 -12
  58. data/test/pipelining_commands_test.rb +135 -126
  59. data/test/publish_subscribe_test.rb +105 -110
  60. data/test/remote_server_control_commands_test.rb +74 -58
  61. data/test/sorting_test.rb +31 -29
  62. data/test/support/connection/hiredis.rb +1 -0
  63. data/test/support/connection/ruby.rb +1 -0
  64. data/test/support/connection/synchrony.rb +17 -0
  65. data/test/{redis_mock.rb → support/redis_mock.rb} +24 -21
  66. data/test/support/wire/synchrony.rb +24 -0
  67. data/test/support/wire/thread.rb +5 -0
  68. data/test/synchrony_driver.rb +9 -9
  69. data/test/test.conf +1 -1
  70. data/test/thread_safety_test.rb +21 -19
  71. data/test/transactions_test.rb +189 -118
  72. data/test/unknown_commands_test.rb +9 -8
  73. data/test/url_param_test.rb +46 -41
  74. metadata +28 -43
  75. data/TODO.md +0 -4
  76. data/benchmarking/thread_safety.rb +0 -38
  77. data/test/lint/internals.rb +0 -36
@@ -1,90 +1,96 @@
1
- test "SADD" do |r|
2
- assert true == r.sadd("foo", "s1")
3
- assert true == r.sadd("foo", "s2")
4
- assert false == r.sadd("foo", "s1")
1
+ module Lint
5
2
 
6
- assert ["s1", "s2"] == r.smembers("foo").sort
7
- end
3
+ module Sets
8
4
 
9
- test "Variadic SADD" do |r|
10
- next if version(r) < 203090 # 2.4-rc6
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")
11
9
 
12
- assert 2 == r.sadd("foo", ["s1", "s2"])
13
- assert 1 == r.sadd("foo", ["s1", "s2", "s3"])
10
+ assert_equal ["s1", "s2"], r.smembers("foo").sort
11
+ end
14
12
 
15
- assert ["s1", "s2", "s3"] == r.smembers("foo").sort
16
- end
13
+ def test_variadic_sadd
14
+ return if version < "2.3.9" # 2.4-rc6
17
15
 
18
- test "SREM" do |r|
19
- r.sadd("foo", "s1")
20
- r.sadd("foo", "s2")
16
+ assert_equal 2, r.sadd("foo", ["s1", "s2"])
17
+ assert_equal 1, r.sadd("foo", ["s1", "s2", "s3"])
21
18
 
22
- assert true == r.srem("foo", "s1")
23
- assert false == r.srem("foo", "s3")
19
+ assert_equal ["s1", "s2", "s3"], r.smembers("foo").sort
20
+ end
24
21
 
25
- assert ["s2"] == r.smembers("foo")
26
- end
22
+ def test_srem
23
+ r.sadd("foo", "s1")
24
+ r.sadd("foo", "s2")
27
25
 
28
- test "Variadic SREM" do |r|
29
- next if version(r) < 203090 # 2.4-rc6
26
+ assert_equal true, r.srem("foo", "s1")
27
+ assert_equal false, r.srem("foo", "s3")
30
28
 
31
- r.sadd("foo", "s1")
32
- r.sadd("foo", "s2")
33
- r.sadd("foo", "s3")
29
+ assert_equal ["s2"], r.smembers("foo")
30
+ end
34
31
 
35
- assert 1 == r.srem("foo", ["s1", "aaa"])
36
- assert 0 == r.srem("foo", ["bbb", "ccc" "ddd"])
37
- assert 1 == r.srem("foo", ["eee", "s3"])
32
+ def test_variadic_srem
33
+ return if version < "2.3.9" # 2.4-rc6
38
34
 
39
- assert ["s2"] == r.smembers("foo")
40
- end
35
+ r.sadd("foo", "s1")
36
+ r.sadd("foo", "s2")
37
+ r.sadd("foo", "s3")
41
38
 
42
- test "SPOP" do |r|
43
- r.sadd "foo", "s1"
44
- r.sadd "foo", "s2"
39
+ assert_equal 1, r.srem("foo", ["s1", "aaa"])
40
+ assert_equal 0, r.srem("foo", ["bbb", "ccc" "ddd"])
41
+ assert_equal 1, r.srem("foo", ["eee", "s3"])
45
42
 
46
- assert ["s1", "s2"].include?(r.spop("foo"))
47
- assert ["s1", "s2"].include?(r.spop("foo"))
48
- assert nil == r.spop("foo")
49
- end
43
+ assert_equal ["s2"], r.smembers("foo")
44
+ end
50
45
 
51
- test "SCARD" do |r|
52
- assert 0 == r.scard("foo")
46
+ def test_spop
47
+ r.sadd "foo", "s1"
48
+ r.sadd "foo", "s2"
53
49
 
54
- r.sadd "foo", "s1"
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
55
54
 
56
- assert 1 == r.scard("foo")
55
+ def test_scard
56
+ assert_equal 0, r.scard("foo")
57
57
 
58
- r.sadd "foo", "s2"
58
+ r.sadd "foo", "s1"
59
59
 
60
- assert 2 == r.scard("foo")
61
- end
60
+ assert_equal 1, r.scard("foo")
62
61
 
63
- test "SISMEMBER" do |r|
64
- assert false == r.sismember("foo", "s1")
62
+ r.sadd "foo", "s2"
65
63
 
66
- r.sadd "foo", "s1"
64
+ assert_equal 2, r.scard("foo")
65
+ end
67
66
 
68
- assert true == r.sismember("foo", "s1")
69
- assert false == r.sismember("foo", "s2")
70
- end
67
+ def test_sismember
68
+ assert_equal false, r.sismember("foo", "s1")
71
69
 
72
- test "SMEMBERS" do |r|
73
- assert [] == r.smembers("foo")
70
+ r.sadd "foo", "s1"
74
71
 
75
- r.sadd "foo", "s1"
76
- r.sadd "foo", "s2"
72
+ assert_equal true, r.sismember("foo", "s1")
73
+ assert_equal false, r.sismember("foo", "s2")
74
+ end
77
75
 
78
- assert ["s1", "s2"] == r.smembers("foo").sort
79
- end
76
+ def test_smembers
77
+ assert_equal [], r.smembers("foo")
80
78
 
81
- test "SRANDMEMBER" do |r|
82
- r.sadd "foo", "s1"
83
- r.sadd "foo", "s2"
79
+ r.sadd "foo", "s1"
80
+ r.sadd "foo", "s2"
84
81
 
85
- 4.times do
86
- assert ["s1", "s2"].include?(r.srandmember("foo"))
87
- end
82
+ assert_equal ["s1", "s2"], r.smembers("foo").sort
83
+ end
88
84
 
89
- assert 2 == r.scard("foo")
85
+ def test_srandmember
86
+ r.sadd "foo", "s1"
87
+ r.sadd "foo", "s2"
88
+
89
+ 4.times do
90
+ assert ["s1", "s2"].include?(r.srandmember("foo"))
91
+ end
92
+
93
+ assert_equal 2, r.scard("foo")
94
+ end
95
+ end
90
96
  end
@@ -1,196 +1,201 @@
1
- test "ZADD" do |r|
2
- assert 0 == r.zcard("foo")
3
- assert true == r.zadd("foo", 1, "s1")
4
- assert false == r.zadd("foo", 1, "s1")
5
- assert 1 == r.zcard("foo")
6
- end
7
-
8
- test "Variadic ZADD" do |r|
9
- next if version(r) < 203090 # 2.4-rc6
10
-
11
- # Non-nested array with pairs
12
- assert 0 == r.zcard("foo")
13
- assert 2 == r.zadd("foo", [1, "s1", 2, "s2"])
14
- assert 1 == r.zadd("foo", [4, "s1", 5, "s2", 6, "s3"])
15
- assert 3 == r.zcard("foo")
16
- r.del "foo"
17
-
18
- # Nested array with pairs
19
- assert 0 == r.zcard("foo")
20
- assert 2 == r.zadd("foo", [[1, "s1"], [2, "s2"]])
21
- assert 1 == r.zadd("foo", [[4, "s1"], [5, "s2"], [6, "s3"]])
22
- assert 3 == r.zcard("foo")
23
- r.del "foo"
24
-
25
- # Wrong number of arguments
26
- assert_raise { r.zadd("foo") }
27
- assert_raise { r.zadd("foo", ["bar"]) }
28
- assert_raise { r.zadd("foo", ["bar", "qux", "zap"]) }
29
- end
30
-
31
- test "ZREM" do |r|
32
- r.zadd("foo", 1, "s1")
33
- r.zadd("foo", 2, "s2")
34
-
35
- assert 2 == r.zcard("foo")
36
- assert true == r.zrem("foo", "s1")
37
- assert false == r.zrem("foo", "s1")
38
- assert 1 == r.zcard("foo")
39
- end
40
-
41
- test "Variadic ZREM" do |r|
42
- next if version(r) < 203090 # 2.4-rc6
43
-
44
- r.zadd("foo", 1, "s1")
45
- r.zadd("foo", 2, "s2")
46
- r.zadd("foo", 3, "s3")
47
-
48
- assert 3 == r.zcard("foo")
49
- assert 1 == r.zrem("foo", ["s1", "aaa"])
50
- assert 0 == r.zrem("foo", ["bbb", "ccc" "ddd"])
51
- assert 1 == r.zrem("foo", ["eee", "s3"])
52
- assert 1 == r.zcard("foo")
53
- end
54
-
55
- test "ZINCRBY" do |r|
56
- rv = r.zincrby "foo", 1, "s1"
57
- assert 1.0 == rv
58
-
59
- rv = r.zincrby "foo", 10, "s1"
60
- assert 11.0 == rv
61
- end
62
-
63
- test "ZRANK" do |r|
64
- r.zadd "foo", 1, "s1"
65
- r.zadd "foo", 2, "s2"
66
- r.zadd "foo", 3, "s3"
67
-
68
- assert 2 == r.zrank("foo", "s3")
69
- end
70
-
71
- test "ZREVRANK" do |r|
72
- r.zadd "foo", 1, "s1"
73
- r.zadd "foo", 2, "s2"
74
- r.zadd "foo", 3, "s3"
75
-
76
- assert 0 == r.zrevrank("foo", "s3")
77
- end
78
-
79
- test "ZRANGE" do |r|
80
- r.zadd "foo", 1, "s1"
81
- r.zadd "foo", 2, "s2"
82
- r.zadd "foo", 3, "s3"
83
-
84
- assert ["s1", "s2"] == r.zrange("foo", 0, 1)
85
- assert [["s1", 1.0], ["s2", 2.0]] == r.zrange("foo", 0, 1, :with_scores => true)
86
- assert [["s1", 1.0], ["s2", 2.0]] == r.zrange("foo", 0, 1, :withscores => true)
87
- end
88
-
89
- test "ZREVRANGE" do |r|
90
- r.zadd "foo", 1, "s1"
91
- r.zadd "foo", 2, "s2"
92
- r.zadd "foo", 3, "s3"
93
-
94
- assert ["s3", "s2"] == r.zrevrange("foo", 0, 1)
95
- assert [["s3", 3.0], ["s2", 2.0]] == r.zrevrange("foo", 0, 1, :with_scores => true)
96
- assert [["s3", 3.0], ["s2", 2.0]] == r.zrevrange("foo", 0, 1, :withscores => true)
97
- end
98
-
99
- test "ZRANGEBYSCORE" do |r|
100
- r.zadd "foo", 1, "s1"
101
- r.zadd "foo", 2, "s2"
102
- r.zadd "foo", 3, "s3"
103
-
104
- assert ["s2", "s3"] == r.zrangebyscore("foo", 2, 3)
105
- end
106
-
107
- test "ZREVRANGEBYSCORE" do |r|
108
- r.zadd "foo", 1, "s1"
109
- r.zadd "foo", 2, "s2"
110
- r.zadd "foo", 3, "s3"
111
-
112
- assert ["s3", "s2"] == r.zrevrangebyscore("foo", 3, 2)
113
- end
114
-
115
- test "ZRANGEBYSCORE with LIMIT" do |r|
116
- r.zadd "foo", 1, "s1"
117
- r.zadd "foo", 2, "s2"
118
- r.zadd "foo", 3, "s3"
119
- r.zadd "foo", 4, "s4"
120
-
121
- assert ["s2"] == r.zrangebyscore("foo", 2, 4, :limit => [0, 1])
122
- assert ["s3"] == r.zrangebyscore("foo", 2, 4, :limit => [1, 1])
123
- assert ["s3", "s4"] == r.zrangebyscore("foo", 2, 4, :limit => [1, 2])
124
- end
125
-
126
- test "ZREVRANGEBYSCORE with LIMIT" do |r|
127
- r.zadd "foo", 1, "s1"
128
- r.zadd "foo", 2, "s2"
129
- r.zadd "foo", 3, "s3"
130
- r.zadd "foo", 4, "s4"
131
-
132
- assert ["s4"] == r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1])
133
- assert ["s3"] == r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1])
134
- assert ["s3", "s2"] == r.zrevrangebyscore("foo", 4, 2, :limit => [1, 2])
135
- end
136
-
137
- test "ZRANGEBYSCORE with WITHSCORES" do |r|
138
- r.zadd "foo", 1, "s1"
139
- r.zadd "foo", 2, "s2"
140
- r.zadd "foo", 3, "s3"
141
- r.zadd "foo", 4, "s4"
142
-
143
- assert [["s2", 2.0]] == r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :with_scores => true)
144
- assert [["s3", 3.0]] == r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :with_scores => true)
145
- assert [["s2", 2.0]] == r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :withscores => true)
146
- assert [["s3", 3.0]] == r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :withscores => true)
147
- end
148
-
149
- test "ZREVRANGEBYSCORE with WITHSCORES" do |r|
150
- r.zadd "foo", 1, "s1"
151
- r.zadd "foo", 2, "s2"
152
- r.zadd "foo", 3, "s3"
153
- r.zadd "foo", 4, "s4"
154
-
155
- assert [["s4", 4.0]] == r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :with_scores => true)
156
- assert [["s3", 3.0]] == r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :with_scores => true)
157
- assert [["s4", 4.0]] == r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :withscores => true)
158
- assert [["s3", 3.0]] == r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :withscores => true)
159
- end
160
-
161
- test "ZCARD" do |r|
162
- assert 0 == r.zcard("foo")
163
-
164
- r.zadd "foo", 1, "s1"
165
-
166
- assert 1 == r.zcard("foo")
167
- end
168
-
169
- test "ZSCORE" do |r|
170
- r.zadd "foo", 1, "s1"
171
-
172
- assert 1.0 == r.zscore("foo", "s1")
173
-
174
- assert nil == r.zscore("foo", "s2")
175
- assert nil == r.zscore("bar", "s1")
176
- end
177
-
178
- test "ZREMRANGEBYRANK" do |r|
179
- r.zadd "foo", 10, "s1"
180
- r.zadd "foo", 20, "s2"
181
- r.zadd "foo", 30, "s3"
182
- r.zadd "foo", 40, "s4"
183
-
184
- assert 3 == r.zremrangebyrank("foo", 1, 3)
185
- assert ["s1"] == r.zrange("foo", 0, -1)
186
- end
187
-
188
- test "ZREMRANGEBYSCORE" do |r|
189
- r.zadd "foo", 1, "s1"
190
- r.zadd "foo", 2, "s2"
191
- r.zadd "foo", 3, "s3"
192
- r.zadd "foo", 4, "s4"
193
-
194
- assert 3 == r.zremrangebyscore("foo", 2, 4)
195
- assert ["s1"] == r.zrange("foo", 0, -1)
1
+ module Lint
2
+
3
+ module SortedSets
4
+
5
+ def test_zadd
6
+ assert_equal 0, r.zcard("foo")
7
+ assert_equal true, r.zadd("foo", 1, "s1")
8
+ assert_equal false, r.zadd("foo", 1, "s1")
9
+ assert_equal 1, r.zcard("foo")
10
+ end
11
+
12
+ def test_variadic_zadd
13
+ return if version < "2.3.9" # 2.4-rc6
14
+
15
+ # Non-nested array with pairs
16
+ assert_equal 0, r.zcard("foo")
17
+ assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"])
18
+ assert_equal 1, r.zadd("foo", [4, "s1", 5, "s2", 6, "s3"])
19
+ assert_equal 3, r.zcard("foo")
20
+ r.del "foo"
21
+
22
+ # Nested array with pairs
23
+ assert_equal 0, r.zcard("foo")
24
+ assert_equal 2, r.zadd("foo", [[1, "s1"], [2, "s2"]])
25
+ assert_equal 1, r.zadd("foo", [[4, "s1"], [5, "s2"], [6, "s3"]])
26
+ assert_equal 3, r.zcard("foo")
27
+ r.del "foo"
28
+
29
+ # Wrong number of arguments
30
+ assert_raise(Redis::CommandError) { r.zadd("foo", ["bar"]) }
31
+ assert_raise(Redis::CommandError) { r.zadd("foo", ["bar", "qux", "zap"]) }
32
+ end
33
+
34
+ def test_zrem
35
+ r.zadd("foo", 1, "s1")
36
+ r.zadd("foo", 2, "s2")
37
+
38
+ assert_equal 2, r.zcard("foo")
39
+ assert_equal true, r.zrem("foo", "s1")
40
+ assert_equal false, r.zrem("foo", "s1")
41
+ assert_equal 1, r.zcard("foo")
42
+ end
43
+
44
+ def test_variadic_zrem
45
+ return if version < "2.3.9" # 2.4-rc6
46
+
47
+ r.zadd("foo", 1, "s1")
48
+ r.zadd("foo", 2, "s2")
49
+ r.zadd("foo", 3, "s3")
50
+
51
+ assert_equal 3, r.zcard("foo")
52
+ assert_equal 1, r.zrem("foo", ["s1", "aaa"])
53
+ assert_equal 0, r.zrem("foo", ["bbb", "ccc" "ddd"])
54
+ assert_equal 1, r.zrem("foo", ["eee", "s3"])
55
+ assert_equal 1, r.zcard("foo")
56
+ end
57
+
58
+ def test_zincrby
59
+ rv = r.zincrby "foo", 1, "s1"
60
+ assert_equal 1.0, rv
61
+
62
+ rv = r.zincrby "foo", 10, "s1"
63
+ assert_equal 11.0, rv
64
+ end
65
+
66
+ def test_zrank
67
+ r.zadd "foo", 1, "s1"
68
+ r.zadd "foo", 2, "s2"
69
+ r.zadd "foo", 3, "s3"
70
+
71
+ assert_equal 2, r.zrank("foo", "s3")
72
+ end
73
+
74
+ def test_zrevrank
75
+ r.zadd "foo", 1, "s1"
76
+ r.zadd "foo", 2, "s2"
77
+ r.zadd "foo", 3, "s3"
78
+
79
+ assert_equal 0, r.zrevrank("foo", "s3")
80
+ end
81
+
82
+ def test_zrange
83
+ r.zadd "foo", 1, "s1"
84
+ r.zadd "foo", 2, "s2"
85
+ r.zadd "foo", 3, "s3"
86
+
87
+ assert_equal ["s1", "s2"], r.zrange("foo", 0, 1)
88
+ assert_equal [["s1", 1.0], ["s2", 2.0]], r.zrange("foo", 0, 1, :with_scores => true)
89
+ assert_equal [["s1", 1.0], ["s2", 2.0]], r.zrange("foo", 0, 1, :withscores => true)
90
+ end
91
+
92
+ def test_zrevrange
93
+ r.zadd "foo", 1, "s1"
94
+ r.zadd "foo", 2, "s2"
95
+ r.zadd "foo", 3, "s3"
96
+
97
+ assert_equal ["s3", "s2"], r.zrevrange("foo", 0, 1)
98
+ assert_equal [["s3", 3.0], ["s2", 2.0]], r.zrevrange("foo", 0, 1, :with_scores => true)
99
+ assert_equal [["s3", 3.0], ["s2", 2.0]], r.zrevrange("foo", 0, 1, :withscores => true)
100
+ end
101
+
102
+ def test_zrangebyscore
103
+ r.zadd "foo", 1, "s1"
104
+ r.zadd "foo", 2, "s2"
105
+ r.zadd "foo", 3, "s3"
106
+
107
+ assert_equal ["s2", "s3"], r.zrangebyscore("foo", 2, 3)
108
+ end
109
+
110
+ def test_zrevrangebyscore
111
+ r.zadd "foo", 1, "s1"
112
+ r.zadd "foo", 2, "s2"
113
+ r.zadd "foo", 3, "s3"
114
+
115
+ assert_equal ["s3", "s2"], r.zrevrangebyscore("foo", 3, 2)
116
+ end
117
+
118
+ def test_zrangebyscore_with_limit
119
+ r.zadd "foo", 1, "s1"
120
+ r.zadd "foo", 2, "s2"
121
+ r.zadd "foo", 3, "s3"
122
+ r.zadd "foo", 4, "s4"
123
+
124
+ assert_equal ["s2"], r.zrangebyscore("foo", 2, 4, :limit => [0, 1])
125
+ assert_equal ["s3"], r.zrangebyscore("foo", 2, 4, :limit => [1, 1])
126
+ assert_equal ["s3", "s4"], r.zrangebyscore("foo", 2, 4, :limit => [1, 2])
127
+ end
128
+
129
+ def test_zrevrangebyscore_with_limit
130
+ r.zadd "foo", 1, "s1"
131
+ r.zadd "foo", 2, "s2"
132
+ r.zadd "foo", 3, "s3"
133
+ r.zadd "foo", 4, "s4"
134
+
135
+ assert_equal ["s4"], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1])
136
+ assert_equal ["s3"], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1])
137
+ assert_equal ["s3", "s2"], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 2])
138
+ end
139
+
140
+ def test_zrangebyscore_with_withscores
141
+ r.zadd "foo", 1, "s1"
142
+ r.zadd "foo", 2, "s2"
143
+ r.zadd "foo", 3, "s3"
144
+ r.zadd "foo", 4, "s4"
145
+
146
+ assert_equal [["s2", 2.0]], r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :with_scores => true)
147
+ assert_equal [["s3", 3.0]], r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :with_scores => true)
148
+ assert_equal [["s2", 2.0]], r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :withscores => true)
149
+ assert_equal [["s3", 3.0]], r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :withscores => true)
150
+ end
151
+
152
+ def test_zrevrangebyscore_with_withscores
153
+ r.zadd "foo", 1, "s1"
154
+ r.zadd "foo", 2, "s2"
155
+ r.zadd "foo", 3, "s3"
156
+ r.zadd "foo", 4, "s4"
157
+
158
+ assert_equal [["s4", 4.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :with_scores => true)
159
+ assert_equal [["s3", 3.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :with_scores => true)
160
+ assert_equal [["s4", 4.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :withscores => true)
161
+ assert_equal [["s3", 3.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :withscores => true)
162
+ end
163
+
164
+ def test_zcard
165
+ assert_equal 0, r.zcard("foo")
166
+
167
+ r.zadd "foo", 1, "s1"
168
+
169
+ assert_equal 1, r.zcard("foo")
170
+ end
171
+
172
+ def test_zscore
173
+ r.zadd "foo", 1, "s1"
174
+
175
+ assert_equal 1.0, r.zscore("foo", "s1")
176
+
177
+ assert_equal nil, r.zscore("foo", "s2")
178
+ assert_equal nil, r.zscore("bar", "s1")
179
+ end
180
+
181
+ def test_zremrangebyrank
182
+ r.zadd "foo", 10, "s1"
183
+ r.zadd "foo", 20, "s2"
184
+ r.zadd "foo", 30, "s3"
185
+ r.zadd "foo", 40, "s4"
186
+
187
+ assert_equal 3, r.zremrangebyrank("foo", 1, 3)
188
+ assert_equal ["s1"], r.zrange("foo", 0, -1)
189
+ end
190
+
191
+ def test_zremrangebyscore
192
+ r.zadd "foo", 1, "s1"
193
+ r.zadd "foo", 2, "s2"
194
+ r.zadd "foo", 3, "s3"
195
+ r.zadd "foo", 4, "s4"
196
+
197
+ assert_equal 3, r.zremrangebyscore("foo", 2, 4)
198
+ assert_equal ["s1"], r.zrange("foo", 0, -1)
199
+ end
200
+ end
196
201
  end