gorsuch-redis 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +113 -0
- data/LICENSE +20 -0
- data/README.md +214 -0
- data/Rakefile +260 -0
- data/TODO.md +4 -0
- data/benchmarking/logging.rb +62 -0
- data/benchmarking/pipeline.rb +51 -0
- data/benchmarking/speed.rb +21 -0
- data/benchmarking/suite.rb +24 -0
- data/benchmarking/thread_safety.rb +38 -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 +31 -0
- data/examples/sets.rb +36 -0
- data/examples/unicorn/config.ru +3 -0
- data/examples/unicorn/unicorn.rb +20 -0
- data/lib/redis/client.rb +303 -0
- data/lib/redis/connection/command_helper.rb +44 -0
- data/lib/redis/connection/hiredis.rb +52 -0
- data/lib/redis/connection/registry.rb +12 -0
- data/lib/redis/connection/ruby.rb +136 -0
- data/lib/redis/connection/synchrony.rb +131 -0
- data/lib/redis/connection.rb +9 -0
- data/lib/redis/distributed.rb +696 -0
- data/lib/redis/errors.rb +38 -0
- data/lib/redis/hash_ring.rb +131 -0
- data/lib/redis/pipeline.rb +106 -0
- data/lib/redis/subscribe.rb +79 -0
- data/lib/redis/version.rb +3 -0
- data/lib/redis.rb +1724 -0
- data/redis.gemspec +43 -0
- data/test/command_map_test.rb +29 -0
- data/test/commands_on_hashes_test.rb +20 -0
- data/test/commands_on_lists_test.rb +60 -0
- data/test/commands_on_sets_test.rb +76 -0
- data/test/commands_on_sorted_sets_test.rb +108 -0
- data/test/commands_on_strings_test.rb +80 -0
- data/test/commands_on_value_types_test.rb +87 -0
- data/test/connection_handling_test.rb +204 -0
- data/test/db/.gitignore +1 -0
- data/test/distributed_blocking_commands_test.rb +53 -0
- data/test/distributed_commands_on_hashes_test.rb +11 -0
- data/test/distributed_commands_on_lists_test.rb +23 -0
- data/test/distributed_commands_on_sets_test.rb +84 -0
- data/test/distributed_commands_on_sorted_sets_test.rb +19 -0
- data/test/distributed_commands_on_strings_test.rb +49 -0
- data/test/distributed_commands_on_value_types_test.rb +72 -0
- data/test/distributed_commands_requiring_clustering_test.rb +148 -0
- data/test/distributed_connection_handling_test.rb +24 -0
- data/test/distributed_internals_test.rb +27 -0
- data/test/distributed_key_tags_test.rb +52 -0
- data/test/distributed_persistence_control_commands_test.rb +23 -0
- data/test/distributed_publish_subscribe_test.rb +100 -0
- data/test/distributed_remote_server_control_commands_test.rb +42 -0
- data/test/distributed_sorting_test.rb +21 -0
- data/test/distributed_test.rb +59 -0
- data/test/distributed_transactions_test.rb +33 -0
- data/test/encoding_test.rb +15 -0
- data/test/error_replies_test.rb +53 -0
- data/test/helper.rb +155 -0
- data/test/helper_test.rb +8 -0
- data/test/internals_test.rb +152 -0
- data/test/lint/hashes.rb +140 -0
- data/test/lint/internals.rb +36 -0
- data/test/lint/lists.rb +107 -0
- data/test/lint/sets.rb +90 -0
- data/test/lint/sorted_sets.rb +196 -0
- data/test/lint/strings.rb +133 -0
- data/test/lint/value_types.rb +81 -0
- data/test/persistence_control_commands_test.rb +21 -0
- data/test/pipelining_commands_test.rb +186 -0
- data/test/publish_subscribe_test.rb +158 -0
- data/test/redis_mock.rb +89 -0
- data/test/remote_server_control_commands_test.rb +88 -0
- data/test/sorting_test.rb +43 -0
- data/test/synchrony_driver.rb +57 -0
- data/test/test.conf +9 -0
- data/test/thread_safety_test.rb +30 -0
- data/test/transactions_test.rb +173 -0
- data/test/unknown_commands_test.rb +13 -0
- data/test/url_param_test.rb +59 -0
- metadata +236 -0
data/test/lint/hashes.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
test "HSET and HGET" do |r|
|
2
|
+
r.hset("foo", "f1", "s1")
|
3
|
+
|
4
|
+
assert "s1" == r.hget("foo", "f1")
|
5
|
+
end
|
6
|
+
|
7
|
+
test "HSETNX" do |r|
|
8
|
+
r.hset("foo", "f1", "s1")
|
9
|
+
r.hsetnx("foo", "f1", "s2")
|
10
|
+
|
11
|
+
assert "s1" == r.hget("foo", "f1")
|
12
|
+
|
13
|
+
r.del("foo")
|
14
|
+
r.hsetnx("foo", "f1", "s2")
|
15
|
+
|
16
|
+
assert "s2" == r.hget("foo", "f1")
|
17
|
+
end
|
18
|
+
|
19
|
+
test "HDEL" do |r|
|
20
|
+
r.hset("foo", "f1", "s1")
|
21
|
+
|
22
|
+
assert "s1" == r.hget("foo", "f1")
|
23
|
+
|
24
|
+
assert 1 == r.hdel("foo", "f1")
|
25
|
+
|
26
|
+
assert nil == r.hget("foo", "f1")
|
27
|
+
end
|
28
|
+
|
29
|
+
test "Variadic HDEL" do |r|
|
30
|
+
next if version(r) < 203090
|
31
|
+
|
32
|
+
r.hset("foo", "f1", "s1")
|
33
|
+
r.hset("foo", "f2", "s2")
|
34
|
+
|
35
|
+
assert "s1" == r.hget("foo", "f1")
|
36
|
+
assert "s2" == r.hget("foo", "f2")
|
37
|
+
|
38
|
+
assert 2 == r.hdel("foo", ["f1", "f2"])
|
39
|
+
|
40
|
+
assert nil == r.hget("foo", "f1")
|
41
|
+
assert nil == r.hget("foo", "f2")
|
42
|
+
end
|
43
|
+
|
44
|
+
test "HEXISTS" do |r|
|
45
|
+
assert false == r.hexists("foo", "f1")
|
46
|
+
|
47
|
+
r.hset("foo", "f1", "s1")
|
48
|
+
|
49
|
+
assert r.hexists("foo", "f1")
|
50
|
+
end
|
51
|
+
|
52
|
+
test "HLEN" do |r|
|
53
|
+
assert 0 == r.hlen("foo")
|
54
|
+
|
55
|
+
r.hset("foo", "f1", "s1")
|
56
|
+
|
57
|
+
assert 1 == r.hlen("foo")
|
58
|
+
|
59
|
+
r.hset("foo", "f2", "s2")
|
60
|
+
|
61
|
+
assert 2 == r.hlen("foo")
|
62
|
+
end
|
63
|
+
|
64
|
+
test "HKEYS" do |r|
|
65
|
+
assert [] == r.hkeys("foo")
|
66
|
+
|
67
|
+
r.hset("foo", "f1", "s1")
|
68
|
+
r.hset("foo", "f2", "s2")
|
69
|
+
|
70
|
+
assert ["f1", "f2"] == r.hkeys("foo")
|
71
|
+
end
|
72
|
+
|
73
|
+
test "HVALS" do |r|
|
74
|
+
assert [] == r.hvals("foo")
|
75
|
+
|
76
|
+
r.hset("foo", "f1", "s1")
|
77
|
+
r.hset("foo", "f2", "s2")
|
78
|
+
|
79
|
+
assert ["s1", "s2"] == r.hvals("foo")
|
80
|
+
end
|
81
|
+
|
82
|
+
test "HGETALL" do |r|
|
83
|
+
assert({} == r.hgetall("foo"))
|
84
|
+
|
85
|
+
r.hset("foo", "f1", "s1")
|
86
|
+
r.hset("foo", "f2", "s2")
|
87
|
+
|
88
|
+
assert({"f1" => "s1", "f2" => "s2"} == r.hgetall("foo"))
|
89
|
+
end
|
90
|
+
|
91
|
+
test "HMSET" do |r|
|
92
|
+
r.hmset("hash", "foo1", "bar1", "foo2", "bar2")
|
93
|
+
|
94
|
+
assert "bar1" == r.hget("hash", "foo1")
|
95
|
+
assert "bar2" == r.hget("hash", "foo2")
|
96
|
+
end
|
97
|
+
|
98
|
+
test "HMSET with invalid arguments" do |r|
|
99
|
+
assert_raise(Redis::CommandError) do
|
100
|
+
r.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
test "Mapped HMSET" do |r|
|
105
|
+
r.mapped_hmset("foo", :f1 => "s1", :f2 => "s2")
|
106
|
+
|
107
|
+
assert "s1" == r.hget("foo", "f1")
|
108
|
+
assert "s2" == r.hget("foo", "f2")
|
109
|
+
end
|
110
|
+
|
111
|
+
test "HMGET" do |r|
|
112
|
+
r.hset("foo", "f1", "s1")
|
113
|
+
r.hset("foo", "f2", "s2")
|
114
|
+
r.hset("foo", "f3", "s3")
|
115
|
+
|
116
|
+
assert ["s2", "s3"] == r.hmget("foo", "f2", "f3")
|
117
|
+
end
|
118
|
+
|
119
|
+
test "HMGET mapped" do |r|
|
120
|
+
r.hset("foo", "f1", "s1")
|
121
|
+
r.hset("foo", "f2", "s2")
|
122
|
+
r.hset("foo", "f3", "s3")
|
123
|
+
|
124
|
+
assert({"f1" => "s1"} == r.mapped_hmget("foo", "f1"))
|
125
|
+
assert({"f1" => "s1", "f2" => "s2"} == r.mapped_hmget("foo", "f1", "f2"))
|
126
|
+
end
|
127
|
+
|
128
|
+
test "HINCRBY" do |r|
|
129
|
+
r.hincrby("foo", "f1", 1)
|
130
|
+
|
131
|
+
assert "1" == r.hget("foo", "f1")
|
132
|
+
|
133
|
+
r.hincrby("foo", "f1", 2)
|
134
|
+
|
135
|
+
assert "3" == r.hget("foo", "f1")
|
136
|
+
|
137
|
+
r.hincrby("foo", "f1", -1)
|
138
|
+
|
139
|
+
assert "2" == r.hget("foo", "f1")
|
140
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
test "Logger" do |r, log|
|
2
|
+
r.ping
|
3
|
+
|
4
|
+
assert log.string =~ /Redis >> PING/
|
5
|
+
assert log.string =~ /Redis >> \d+\.\d+ms/
|
6
|
+
end
|
7
|
+
|
8
|
+
test "Logger with pipelining" do |r, log|
|
9
|
+
r.pipelined do
|
10
|
+
r.set "foo", "bar"
|
11
|
+
r.get "foo"
|
12
|
+
end
|
13
|
+
|
14
|
+
assert log.string["SET foo bar"]
|
15
|
+
assert log.string["GET foo"]
|
16
|
+
end if $TEST_PIPELINING
|
17
|
+
|
18
|
+
test "Recovers from failed commands" do |r, _|
|
19
|
+
# See http://github.com/ezmobius/redis-rb/issues#issue/28
|
20
|
+
|
21
|
+
assert_raise do
|
22
|
+
r.command_that_doesnt_exist
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_nothing_raised do
|
26
|
+
r.info
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
test "raises on protocol errors" do
|
31
|
+
redis_mock(:ping => lambda { |*_| "foo" }) do
|
32
|
+
assert_raise(Redis::ProtocolError) do
|
33
|
+
Redis.connect(:port => 6380).ping
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/test/lint/lists.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
test "RPUSH" do |r|
|
2
|
+
r.rpush "foo", "s1"
|
3
|
+
r.rpush "foo", "s2"
|
4
|
+
|
5
|
+
assert 2 == r.llen("foo")
|
6
|
+
assert "s2" == r.rpop("foo")
|
7
|
+
end
|
8
|
+
|
9
|
+
test "Variadic RPUSH" do |r|
|
10
|
+
next if version(r) < 203090 # 2.4-rc6
|
11
|
+
|
12
|
+
assert 3 == r.rpush("foo", ["s1", "s2", "s3"])
|
13
|
+
assert 3 == r.llen("foo")
|
14
|
+
assert "s3" == r.rpop("foo")
|
15
|
+
end
|
16
|
+
|
17
|
+
test "LPUSH" do |r|
|
18
|
+
r.lpush "foo", "s1"
|
19
|
+
r.lpush "foo", "s2"
|
20
|
+
|
21
|
+
assert 2 == r.llen("foo")
|
22
|
+
assert "s2" == r.lpop("foo")
|
23
|
+
end
|
24
|
+
|
25
|
+
test "Variadic LPUSH" do |r|
|
26
|
+
next if version(r) < 203090 # 2.4-rc6
|
27
|
+
|
28
|
+
assert 3 == r.lpush("foo", ["s1", "s2", "s3"])
|
29
|
+
assert 3 == r.llen("foo")
|
30
|
+
assert "s3" == r.lpop("foo")
|
31
|
+
end
|
32
|
+
|
33
|
+
test "LLEN" do |r|
|
34
|
+
r.rpush "foo", "s1"
|
35
|
+
r.rpush "foo", "s2"
|
36
|
+
|
37
|
+
assert 2 == r.llen("foo")
|
38
|
+
end
|
39
|
+
|
40
|
+
test "LRANGE" do |r|
|
41
|
+
r.rpush "foo", "s1"
|
42
|
+
r.rpush "foo", "s2"
|
43
|
+
r.rpush "foo", "s3"
|
44
|
+
|
45
|
+
assert ["s2", "s3"] == r.lrange("foo", 1, -1)
|
46
|
+
assert ["s1", "s2"] == r.lrange("foo", 0, 1)
|
47
|
+
|
48
|
+
assert [] == r.lrange("bar", 0, -1)
|
49
|
+
end
|
50
|
+
|
51
|
+
test "LTRIM" do |r|
|
52
|
+
r.rpush "foo", "s1"
|
53
|
+
r.rpush "foo", "s2"
|
54
|
+
r.rpush "foo", "s3"
|
55
|
+
|
56
|
+
r.ltrim "foo", 0, 1
|
57
|
+
|
58
|
+
assert 2 == r.llen("foo")
|
59
|
+
assert ["s1", "s2"] == r.lrange("foo", 0, -1)
|
60
|
+
end
|
61
|
+
|
62
|
+
test "LINDEX" do |r|
|
63
|
+
r.rpush "foo", "s1"
|
64
|
+
r.rpush "foo", "s2"
|
65
|
+
|
66
|
+
assert "s1" == r.lindex("foo", 0)
|
67
|
+
assert "s2" == r.lindex("foo", 1)
|
68
|
+
end
|
69
|
+
|
70
|
+
test "LSET" do |r|
|
71
|
+
r.rpush "foo", "s1"
|
72
|
+
r.rpush "foo", "s2"
|
73
|
+
|
74
|
+
assert "s2" == r.lindex("foo", 1)
|
75
|
+
assert r.lset("foo", 1, "s3")
|
76
|
+
assert "s3" == r.lindex("foo", 1)
|
77
|
+
|
78
|
+
assert_raise Redis::CommandError do
|
79
|
+
r.lset("foo", 4, "s3")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
test "LREM" do |r|
|
84
|
+
r.rpush "foo", "s1"
|
85
|
+
r.rpush "foo", "s2"
|
86
|
+
|
87
|
+
assert 1 == r.lrem("foo", 1, "s1")
|
88
|
+
assert ["s2"] == r.lrange("foo", 0, -1)
|
89
|
+
end
|
90
|
+
|
91
|
+
test "LPOP" do |r|
|
92
|
+
r.rpush "foo", "s1"
|
93
|
+
r.rpush "foo", "s2"
|
94
|
+
|
95
|
+
assert 2 == r.llen("foo")
|
96
|
+
assert "s1" == r.lpop("foo")
|
97
|
+
assert 1 == r.llen("foo")
|
98
|
+
end
|
99
|
+
|
100
|
+
test "RPOP" do |r|
|
101
|
+
r.rpush "foo", "s1"
|
102
|
+
r.rpush "foo", "s2"
|
103
|
+
|
104
|
+
assert 2 == r.llen("foo")
|
105
|
+
assert "s2" == r.rpop("foo")
|
106
|
+
assert 1 == r.llen("foo")
|
107
|
+
end
|
data/test/lint/sets.rb
ADDED
@@ -0,0 +1,90 @@
|
|
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")
|
5
|
+
|
6
|
+
assert ["s1", "s2"] == r.smembers("foo").sort
|
7
|
+
end
|
8
|
+
|
9
|
+
test "Variadic SADD" do |r|
|
10
|
+
next if version(r) < 203090 # 2.4-rc6
|
11
|
+
|
12
|
+
assert 2 == r.sadd("foo", ["s1", "s2"])
|
13
|
+
assert 1 == r.sadd("foo", ["s1", "s2", "s3"])
|
14
|
+
|
15
|
+
assert ["s1", "s2", "s3"] == r.smembers("foo").sort
|
16
|
+
end
|
17
|
+
|
18
|
+
test "SREM" do |r|
|
19
|
+
r.sadd("foo", "s1")
|
20
|
+
r.sadd("foo", "s2")
|
21
|
+
|
22
|
+
assert true == r.srem("foo", "s1")
|
23
|
+
assert false == r.srem("foo", "s3")
|
24
|
+
|
25
|
+
assert ["s2"] == r.smembers("foo")
|
26
|
+
end
|
27
|
+
|
28
|
+
test "Variadic SREM" do |r|
|
29
|
+
next if version(r) < 203090 # 2.4-rc6
|
30
|
+
|
31
|
+
r.sadd("foo", "s1")
|
32
|
+
r.sadd("foo", "s2")
|
33
|
+
r.sadd("foo", "s3")
|
34
|
+
|
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"])
|
38
|
+
|
39
|
+
assert ["s2"] == r.smembers("foo")
|
40
|
+
end
|
41
|
+
|
42
|
+
test "SPOP" do |r|
|
43
|
+
r.sadd "foo", "s1"
|
44
|
+
r.sadd "foo", "s2"
|
45
|
+
|
46
|
+
assert ["s1", "s2"].include?(r.spop("foo"))
|
47
|
+
assert ["s1", "s2"].include?(r.spop("foo"))
|
48
|
+
assert nil == r.spop("foo")
|
49
|
+
end
|
50
|
+
|
51
|
+
test "SCARD" do |r|
|
52
|
+
assert 0 == r.scard("foo")
|
53
|
+
|
54
|
+
r.sadd "foo", "s1"
|
55
|
+
|
56
|
+
assert 1 == r.scard("foo")
|
57
|
+
|
58
|
+
r.sadd "foo", "s2"
|
59
|
+
|
60
|
+
assert 2 == r.scard("foo")
|
61
|
+
end
|
62
|
+
|
63
|
+
test "SISMEMBER" do |r|
|
64
|
+
assert false == r.sismember("foo", "s1")
|
65
|
+
|
66
|
+
r.sadd "foo", "s1"
|
67
|
+
|
68
|
+
assert true == r.sismember("foo", "s1")
|
69
|
+
assert false == r.sismember("foo", "s2")
|
70
|
+
end
|
71
|
+
|
72
|
+
test "SMEMBERS" do |r|
|
73
|
+
assert [] == r.smembers("foo")
|
74
|
+
|
75
|
+
r.sadd "foo", "s1"
|
76
|
+
r.sadd "foo", "s2"
|
77
|
+
|
78
|
+
assert ["s1", "s2"] == r.smembers("foo").sort
|
79
|
+
end
|
80
|
+
|
81
|
+
test "SRANDMEMBER" do |r|
|
82
|
+
r.sadd "foo", "s1"
|
83
|
+
r.sadd "foo", "s2"
|
84
|
+
|
85
|
+
4.times do
|
86
|
+
assert ["s1", "s2"].include?(r.srandmember("foo"))
|
87
|
+
end
|
88
|
+
|
89
|
+
assert 2 == r.scard("foo")
|
90
|
+
end
|
@@ -0,0 +1,196 @@
|
|
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)
|
196
|
+
end
|