redis 3.3.3 → 5.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +280 -12
- data/README.md +141 -147
- data/lib/redis/client.rb +77 -539
- data/lib/redis/commands/bitmaps.rb +66 -0
- data/lib/redis/commands/cluster.rb +28 -0
- data/lib/redis/commands/connection.rb +53 -0
- data/lib/redis/commands/geo.rb +84 -0
- data/lib/redis/commands/hashes.rb +254 -0
- data/lib/redis/commands/hyper_log_log.rb +37 -0
- data/lib/redis/commands/keys.rb +437 -0
- data/lib/redis/commands/lists.rb +285 -0
- data/lib/redis/commands/pubsub.rb +54 -0
- data/lib/redis/commands/scripting.rb +114 -0
- data/lib/redis/commands/server.rb +188 -0
- data/lib/redis/commands/sets.rb +214 -0
- data/lib/redis/commands/sorted_sets.rb +818 -0
- data/lib/redis/commands/streams.rb +384 -0
- data/lib/redis/commands/strings.rb +314 -0
- data/lib/redis/commands/transactions.rb +115 -0
- data/lib/redis/commands.rb +235 -0
- data/lib/redis/distributed.rb +300 -108
- data/lib/redis/errors.rb +22 -1
- data/lib/redis/hash_ring.rb +36 -79
- data/lib/redis/pipeline.rb +69 -83
- data/lib/redis/subscribe.rb +26 -19
- data/lib/redis/version.rb +3 -1
- data/lib/redis.rb +113 -2685
- metadata +40 -218
- data/.gitignore +0 -16
- data/.travis/Gemfile +0 -11
- data/.travis.yml +0 -89
- data/.yardopts +0 -3
- data/Gemfile +0 -4
- data/Rakefile +0 -87
- data/benchmarking/logging.rb +0 -71
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/examples/basic.rb +0 -15
- data/examples/consistency.rb +0 -114
- data/examples/dist_redis.rb +0 -43
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -37
- data/examples/sentinel/sentinel.conf +0 -9
- data/examples/sentinel/start +0 -49
- data/examples/sentinel.rb +0 -41
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/lib/redis/connection/command_helper.rb +0 -44
- data/lib/redis/connection/hiredis.rb +0 -66
- data/lib/redis/connection/registry.rb +0 -12
- data/lib/redis/connection/ruby.rb +0 -429
- data/lib/redis/connection/synchrony.rb +0 -133
- data/lib/redis/connection.rb +0 -9
- data/redis.gemspec +0 -44
- data/test/bitpos_test.rb +0 -69
- data/test/blocking_commands_test.rb +0 -42
- data/test/client_test.rb +0 -59
- data/test/command_map_test.rb +0 -30
- data/test/commands_on_hashes_test.rb +0 -21
- data/test/commands_on_hyper_log_log_test.rb +0 -21
- data/test/commands_on_lists_test.rb +0 -20
- data/test/commands_on_sets_test.rb +0 -77
- data/test/commands_on_sorted_sets_test.rb +0 -137
- data/test/commands_on_strings_test.rb +0 -101
- data/test/commands_on_value_types_test.rb +0 -133
- data/test/connection_handling_test.rb +0 -277
- data/test/db/.gitkeep +0 -0
- data/test/distributed_blocking_commands_test.rb +0 -46
- data/test/distributed_commands_on_hashes_test.rb +0 -10
- data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
- data/test/distributed_commands_on_lists_test.rb +0 -22
- data/test/distributed_commands_on_sets_test.rb +0 -83
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
- data/test/distributed_commands_on_strings_test.rb +0 -59
- data/test/distributed_commands_on_value_types_test.rb +0 -95
- data/test/distributed_commands_requiring_clustering_test.rb +0 -164
- data/test/distributed_connection_handling_test.rb +0 -23
- data/test/distributed_internals_test.rb +0 -79
- data/test/distributed_key_tags_test.rb +0 -52
- data/test/distributed_persistence_control_commands_test.rb +0 -26
- data/test/distributed_publish_subscribe_test.rb +0 -92
- data/test/distributed_remote_server_control_commands_test.rb +0 -66
- data/test/distributed_scripting_test.rb +0 -102
- data/test/distributed_sorting_test.rb +0 -20
- data/test/distributed_test.rb +0 -58
- data/test/distributed_transactions_test.rb +0 -32
- data/test/encoding_test.rb +0 -18
- data/test/error_replies_test.rb +0 -59
- data/test/fork_safety_test.rb +0 -65
- data/test/helper.rb +0 -232
- data/test/helper_test.rb +0 -24
- data/test/internals_test.rb +0 -457
- data/test/lint/blocking_commands.rb +0 -150
- data/test/lint/hashes.rb +0 -162
- data/test/lint/hyper_log_log.rb +0 -60
- data/test/lint/lists.rb +0 -143
- data/test/lint/sets.rb +0 -140
- data/test/lint/sorted_sets.rb +0 -316
- data/test/lint/strings.rb +0 -260
- data/test/lint/value_types.rb +0 -122
- data/test/persistence_control_commands_test.rb +0 -26
- data/test/pipelining_commands_test.rb +0 -242
- data/test/publish_subscribe_test.rb +0 -282
- data/test/remote_server_control_commands_test.rb +0 -118
- data/test/scanning_test.rb +0 -413
- data/test/scripting_test.rb +0 -78
- data/test/sentinel_command_test.rb +0 -80
- data/test/sentinel_test.rb +0 -255
- data/test/sorting_test.rb +0 -59
- data/test/ssl_test.rb +0 -73
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -130
- data/test/support/ssl/gen_certs.sh +0 -31
- data/test/support/ssl/trusted-ca.crt +0 -25
- data/test/support/ssl/trusted-ca.key +0 -27
- data/test/support/ssl/trusted-cert.crt +0 -81
- data/test/support/ssl/trusted-cert.key +0 -28
- data/test/support/ssl/untrusted-ca.crt +0 -26
- data/test/support/ssl/untrusted-ca.key +0 -27
- data/test/support/ssl/untrusted-cert.crt +0 -82
- data/test/support/ssl/untrusted-cert.key +0 -28
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -88
- data/test/test.conf.erb +0 -9
- data/test/thread_safety_test.rb +0 -62
- data/test/transactions_test.rb +0 -264
- data/test/unknown_commands_test.rb +0 -14
- data/test/url_param_test.rb +0 -138
data/test/lint/hashes.rb
DELETED
@@ -1,162 +0,0 @@
|
|
1
|
-
module Lint
|
2
|
-
|
3
|
-
module Hashes
|
4
|
-
|
5
|
-
def test_hset_and_hget
|
6
|
-
r.hset("foo", "f1", "s1")
|
7
|
-
|
8
|
-
assert_equal "s1", r.hget("foo", "f1")
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_hsetnx
|
12
|
-
r.hset("foo", "f1", "s1")
|
13
|
-
r.hsetnx("foo", "f1", "s2")
|
14
|
-
|
15
|
-
assert_equal "s1", r.hget("foo", "f1")
|
16
|
-
|
17
|
-
r.del("foo")
|
18
|
-
r.hsetnx("foo", "f1", "s2")
|
19
|
-
|
20
|
-
assert_equal "s2", r.hget("foo", "f1")
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_hdel
|
24
|
-
r.hset("foo", "f1", "s1")
|
25
|
-
|
26
|
-
assert_equal "s1", r.hget("foo", "f1")
|
27
|
-
|
28
|
-
assert_equal 1, r.hdel("foo", "f1")
|
29
|
-
|
30
|
-
assert_equal nil, r.hget("foo", "f1")
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_variadic_hdel
|
34
|
-
target_version "2.3.9" do
|
35
|
-
r.hset("foo", "f1", "s1")
|
36
|
-
r.hset("foo", "f2", "s2")
|
37
|
-
|
38
|
-
assert_equal "s1", r.hget("foo", "f1")
|
39
|
-
assert_equal "s2", r.hget("foo", "f2")
|
40
|
-
|
41
|
-
assert_equal 2, r.hdel("foo", ["f1", "f2"])
|
42
|
-
|
43
|
-
assert_equal nil, r.hget("foo", "f1")
|
44
|
-
assert_equal nil, r.hget("foo", "f2")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_hexists
|
49
|
-
assert_equal false, r.hexists("foo", "f1")
|
50
|
-
|
51
|
-
r.hset("foo", "f1", "s1")
|
52
|
-
|
53
|
-
assert r.hexists("foo", "f1")
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_hlen
|
57
|
-
assert_equal 0, r.hlen("foo")
|
58
|
-
|
59
|
-
r.hset("foo", "f1", "s1")
|
60
|
-
|
61
|
-
assert_equal 1, r.hlen("foo")
|
62
|
-
|
63
|
-
r.hset("foo", "f2", "s2")
|
64
|
-
|
65
|
-
assert_equal 2, r.hlen("foo")
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_hkeys
|
69
|
-
assert_equal [], r.hkeys("foo")
|
70
|
-
|
71
|
-
r.hset("foo", "f1", "s1")
|
72
|
-
r.hset("foo", "f2", "s2")
|
73
|
-
|
74
|
-
assert_equal ["f1", "f2"], r.hkeys("foo")
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_hvals
|
78
|
-
assert_equal [], r.hvals("foo")
|
79
|
-
|
80
|
-
r.hset("foo", "f1", "s1")
|
81
|
-
r.hset("foo", "f2", "s2")
|
82
|
-
|
83
|
-
assert_equal ["s1", "s2"], r.hvals("foo")
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_hgetall
|
87
|
-
assert({} == r.hgetall("foo"))
|
88
|
-
|
89
|
-
r.hset("foo", "f1", "s1")
|
90
|
-
r.hset("foo", "f2", "s2")
|
91
|
-
|
92
|
-
assert({"f1" => "s1", "f2" => "s2"} == r.hgetall("foo"))
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_hmset
|
96
|
-
r.hmset("hash", "foo1", "bar1", "foo2", "bar2")
|
97
|
-
|
98
|
-
assert_equal "bar1", r.hget("hash", "foo1")
|
99
|
-
assert_equal "bar2", r.hget("hash", "foo2")
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_hmset_with_invalid_arguments
|
103
|
-
assert_raise(Redis::CommandError) do
|
104
|
-
r.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_mapped_hmset
|
109
|
-
r.mapped_hmset("foo", :f1 => "s1", :f2 => "s2")
|
110
|
-
|
111
|
-
assert_equal "s1", r.hget("foo", "f1")
|
112
|
-
assert_equal "s2", r.hget("foo", "f2")
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_hmget
|
116
|
-
r.hset("foo", "f1", "s1")
|
117
|
-
r.hset("foo", "f2", "s2")
|
118
|
-
r.hset("foo", "f3", "s3")
|
119
|
-
|
120
|
-
assert_equal ["s2", "s3"], r.hmget("foo", "f2", "f3")
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_hmget_mapped
|
124
|
-
r.hset("foo", "f1", "s1")
|
125
|
-
r.hset("foo", "f2", "s2")
|
126
|
-
r.hset("foo", "f3", "s3")
|
127
|
-
|
128
|
-
assert({"f1" => "s1"} == r.mapped_hmget("foo", "f1"))
|
129
|
-
assert({"f1" => "s1", "f2" => "s2"} == r.mapped_hmget("foo", "f1", "f2"))
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_hincrby
|
133
|
-
r.hincrby("foo", "f1", 1)
|
134
|
-
|
135
|
-
assert_equal "1", r.hget("foo", "f1")
|
136
|
-
|
137
|
-
r.hincrby("foo", "f1", 2)
|
138
|
-
|
139
|
-
assert_equal "3", r.hget("foo", "f1")
|
140
|
-
|
141
|
-
r.hincrby("foo", "f1", -1)
|
142
|
-
|
143
|
-
assert_equal "2", r.hget("foo", "f1")
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_hincrbyfloat
|
147
|
-
target_version "2.5.4" do
|
148
|
-
r.hincrbyfloat("foo", "f1", 1.23)
|
149
|
-
|
150
|
-
assert_equal "1.23", r.hget("foo", "f1")
|
151
|
-
|
152
|
-
r.hincrbyfloat("foo", "f1", 0.77)
|
153
|
-
|
154
|
-
assert_equal "2", r.hget("foo", "f1")
|
155
|
-
|
156
|
-
r.hincrbyfloat("foo", "f1", -0.1)
|
157
|
-
|
158
|
-
assert_equal "1.9", r.hget("foo", "f1")
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
data/test/lint/hyper_log_log.rb
DELETED
@@ -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
|