redis 3.3.5 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +32 -50
  3. data/CHANGELOG.md +7 -9
  4. data/Gemfile +0 -1
  5. data/README.md +31 -75
  6. data/benchmarking/logging.rb +1 -1
  7. data/lib/redis.rb +31 -35
  8. data/lib/redis/client.rb +13 -8
  9. data/lib/redis/connection.rb +2 -2
  10. data/lib/redis/connection/command_helper.rb +2 -8
  11. data/lib/redis/connection/hiredis.rb +2 -2
  12. data/lib/redis/connection/ruby.rb +7 -27
  13. data/lib/redis/connection/synchrony.rb +3 -3
  14. data/lib/redis/pipeline.rb +0 -6
  15. data/lib/redis/version.rb +1 -1
  16. data/makefile +42 -0
  17. data/redis.gemspec +4 -8
  18. data/test/bitpos_test.rb +13 -19
  19. data/test/blocking_commands_test.rb +147 -6
  20. data/test/client_test.rb +1 -1
  21. data/test/command_map_test.rb +3 -5
  22. data/test/commands_on_hashes_test.rb +158 -5
  23. data/test/commands_on_hyper_log_log_test.rb +55 -6
  24. data/test/commands_on_lists_test.rb +139 -5
  25. data/test/commands_on_sets_test.rb +136 -5
  26. data/test/commands_on_sorted_sets_test.rb +312 -5
  27. data/test/commands_on_strings_test.rb +243 -6
  28. data/test/commands_on_value_types_test.rb +120 -7
  29. data/test/connection_handling_test.rb +5 -7
  30. data/test/encoding_test.rb +4 -8
  31. data/test/error_replies_test.rb +2 -4
  32. data/test/fork_safety_test.rb +1 -6
  33. data/test/helper.rb +9 -62
  34. data/test/helper_test.rb +1 -3
  35. data/test/internals_test.rb +67 -49
  36. data/test/persistence_control_commands_test.rb +1 -3
  37. data/test/pipelining_commands_test.rb +4 -8
  38. data/test/publish_subscribe_test.rb +1 -3
  39. data/test/remote_server_control_commands_test.rb +61 -4
  40. data/test/scanning_test.rb +1 -7
  41. data/test/scripting_test.rb +1 -3
  42. data/test/sentinel_command_test.rb +1 -3
  43. data/test/sentinel_test.rb +1 -3
  44. data/test/sorting_test.rb +1 -3
  45. data/test/ssl_test.rb +45 -49
  46. data/test/support/connection/hiredis.rb +1 -1
  47. data/test/support/connection/ruby.rb +1 -1
  48. data/test/support/connection/synchrony.rb +1 -1
  49. data/test/synchrony_driver.rb +6 -9
  50. data/test/thread_safety_test.rb +1 -3
  51. data/test/transactions_test.rb +1 -3
  52. data/test/unknown_commands_test.rb +1 -3
  53. data/test/url_param_test.rb +44 -46
  54. metadata +31 -77
  55. data/Rakefile +0 -87
  56. data/examples/dist_redis.rb +0 -43
  57. data/lib/redis/distributed.rb +0 -873
  58. data/lib/redis/hash_ring.rb +0 -132
  59. data/test/connection_test.rb +0 -57
  60. data/test/distributed_blocking_commands_test.rb +0 -46
  61. data/test/distributed_commands_on_hashes_test.rb +0 -10
  62. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  63. data/test/distributed_commands_on_lists_test.rb +0 -22
  64. data/test/distributed_commands_on_sets_test.rb +0 -83
  65. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  66. data/test/distributed_commands_on_strings_test.rb +0 -59
  67. data/test/distributed_commands_on_value_types_test.rb +0 -95
  68. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  69. data/test/distributed_connection_handling_test.rb +0 -23
  70. data/test/distributed_internals_test.rb +0 -79
  71. data/test/distributed_key_tags_test.rb +0 -52
  72. data/test/distributed_persistence_control_commands_test.rb +0 -26
  73. data/test/distributed_publish_subscribe_test.rb +0 -92
  74. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  75. data/test/distributed_scripting_test.rb +0 -102
  76. data/test/distributed_sorting_test.rb +0 -20
  77. data/test/distributed_test.rb +0 -58
  78. data/test/distributed_transactions_test.rb +0 -32
  79. data/test/lint/blocking_commands.rb +0 -150
  80. data/test/lint/hashes.rb +0 -162
  81. data/test/lint/hyper_log_log.rb +0 -60
  82. data/test/lint/lists.rb +0 -143
  83. data/test/lint/sets.rb +0 -140
  84. data/test/lint/sorted_sets.rb +0 -316
  85. data/test/lint/strings.rb +0 -260
  86. data/test/lint/value_types.rb +0 -122
@@ -1,60 +0,0 @@
1
- module Lint
2
-
3
- module HyperLogLog
4
-
5
- def test_pfadd
6
- target_version "2.8.9" do
7
- assert_equal true, r.pfadd("foo", "s1")
8
- assert_equal true, r.pfadd("foo", "s2")
9
- assert_equal false, r.pfadd("foo", "s1")
10
-
11
- assert_equal 2, r.pfcount("foo")
12
- end
13
- end
14
-
15
- def test_variadic_pfadd
16
- target_version "2.8.9" do
17
- assert_equal true, r.pfadd("foo", ["s1", "s2"])
18
- assert_equal true, r.pfadd("foo", ["s1", "s2", "s3"])
19
-
20
- assert_equal 3, r.pfcount("foo")
21
- end
22
- end
23
-
24
- def test_pfcount
25
- target_version "2.8.9" do
26
- assert_equal 0, r.pfcount("foo")
27
-
28
- assert_equal true, r.pfadd("foo", "s1")
29
-
30
- assert_equal 1, r.pfcount("foo")
31
- end
32
- end
33
-
34
- def test_variadic_pfcount
35
- target_version "2.8.9" do
36
- assert_equal 0, r.pfcount(["{1}foo", "{1}bar"])
37
-
38
- assert_equal true, r.pfadd("{1}foo", "s1")
39
- assert_equal true, r.pfadd("{1}bar", "s1")
40
- assert_equal true, r.pfadd("{1}bar", "s2")
41
-
42
- assert_equal 2, r.pfcount("{1}foo", "{1}bar")
43
- end
44
- end
45
-
46
- def test_variadic_pfcount_expanded
47
- target_version "2.8.9" do
48
- assert_equal 0, r.pfcount("{1}foo", "{1}bar")
49
-
50
- assert_equal true, r.pfadd("{1}foo", "s1")
51
- assert_equal true, r.pfadd("{1}bar", "s1")
52
- assert_equal true, r.pfadd("{1}bar", "s2")
53
-
54
- assert_equal 2, r.pfcount("{1}foo", "{1}bar")
55
- end
56
- end
57
-
58
- end
59
-
60
- end
data/test/lint/lists.rb DELETED
@@ -1,143 +0,0 @@
1
- module Lint
2
-
3
- module Lists
4
-
5
- def test_lpush
6
- r.lpush "foo", "s1"
7
- r.lpush "foo", "s2"
8
-
9
- assert_equal 2, r.llen("foo")
10
- assert_equal "s2", r.lpop("foo")
11
- end
12
-
13
- def test_variadic_lpush
14
- target_version "2.3.9" do # 2.4-rc6
15
- assert_equal 3, r.lpush("foo", ["s1", "s2", "s3"])
16
- assert_equal 3, r.llen("foo")
17
- assert_equal "s3", r.lpop("foo")
18
- end
19
- end
20
-
21
- def test_lpushx
22
- r.lpushx "foo", "s1"
23
- r.lpush "foo", "s2"
24
- r.lpushx "foo", "s3"
25
-
26
- assert_equal 2, r.llen("foo")
27
- assert_equal ["s3", "s2"], r.lrange("foo", 0, -1)
28
- end
29
-
30
- def test_rpush
31
- r.rpush "foo", "s1"
32
- r.rpush "foo", "s2"
33
-
34
- assert_equal 2, r.llen("foo")
35
- assert_equal "s2", r.rpop("foo")
36
- end
37
-
38
- def test_variadic_rpush
39
- target_version "2.3.9" do # 2.4-rc6
40
- assert_equal 3, r.rpush("foo", ["s1", "s2", "s3"])
41
- assert_equal 3, r.llen("foo")
42
- assert_equal "s3", r.rpop("foo")
43
- end
44
- end
45
-
46
- def test_rpushx
47
- r.rpushx "foo", "s1"
48
- r.rpush "foo", "s2"
49
- r.rpushx "foo", "s3"
50
-
51
- assert_equal 2, r.llen("foo")
52
- assert_equal ["s2", "s3"], r.lrange("foo", 0, -1)
53
- end
54
-
55
- def test_llen
56
- r.rpush "foo", "s1"
57
- r.rpush "foo", "s2"
58
-
59
- assert_equal 2, r.llen("foo")
60
- end
61
-
62
- def test_lrange
63
- r.rpush "foo", "s1"
64
- r.rpush "foo", "s2"
65
- r.rpush "foo", "s3"
66
-
67
- assert_equal ["s2", "s3"], r.lrange("foo", 1, -1)
68
- assert_equal ["s1", "s2"], r.lrange("foo", 0, 1)
69
-
70
- assert_equal [], r.lrange("bar", 0, -1)
71
- end
72
-
73
- def test_ltrim
74
- r.rpush "foo", "s1"
75
- r.rpush "foo", "s2"
76
- r.rpush "foo", "s3"
77
-
78
- r.ltrim "foo", 0, 1
79
-
80
- assert_equal 2, r.llen("foo")
81
- assert_equal ["s1", "s2"], r.lrange("foo", 0, -1)
82
- end
83
-
84
- def test_lindex
85
- r.rpush "foo", "s1"
86
- r.rpush "foo", "s2"
87
-
88
- assert_equal "s1", r.lindex("foo", 0)
89
- assert_equal "s2", r.lindex("foo", 1)
90
- end
91
-
92
- def test_lset
93
- r.rpush "foo", "s1"
94
- r.rpush "foo", "s2"
95
-
96
- assert_equal "s2", r.lindex("foo", 1)
97
- assert r.lset("foo", 1, "s3")
98
- assert_equal "s3", r.lindex("foo", 1)
99
-
100
- assert_raise Redis::CommandError do
101
- r.lset("foo", 4, "s3")
102
- end
103
- end
104
-
105
- def test_lrem
106
- r.rpush "foo", "s1"
107
- r.rpush "foo", "s2"
108
-
109
- assert_equal 1, r.lrem("foo", 1, "s1")
110
- assert_equal ["s2"], r.lrange("foo", 0, -1)
111
- end
112
-
113
- def test_lpop
114
- r.rpush "foo", "s1"
115
- r.rpush "foo", "s2"
116
-
117
- assert_equal 2, r.llen("foo")
118
- assert_equal "s1", r.lpop("foo")
119
- assert_equal 1, r.llen("foo")
120
- end
121
-
122
- def test_rpop
123
- r.rpush "foo", "s1"
124
- r.rpush "foo", "s2"
125
-
126
- assert_equal 2, r.llen("foo")
127
- assert_equal "s2", r.rpop("foo")
128
- assert_equal 1, r.llen("foo")
129
- end
130
-
131
- def test_linsert
132
- r.rpush "foo", "s1"
133
- r.rpush "foo", "s3"
134
- r.linsert "foo", :before, "s3", "s2"
135
-
136
- assert_equal ["s1", "s2", "s3"], r.lrange("foo", 0, -1)
137
-
138
- assert_raise(Redis::CommandError) do
139
- r.linsert "foo", :anywhere, "s3", "s2"
140
- end
141
- end
142
- end
143
- end
data/test/lint/sets.rb DELETED
@@ -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