redis 4.0.0.rc1 → 4.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +164 -3
  3. data/README.md +127 -18
  4. data/lib/redis/client.rb +164 -93
  5. data/lib/redis/cluster/command.rb +81 -0
  6. data/lib/redis/cluster/command_loader.rb +33 -0
  7. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  8. data/lib/redis/cluster/node.rb +108 -0
  9. data/lib/redis/cluster/node_key.rb +31 -0
  10. data/lib/redis/cluster/node_loader.rb +37 -0
  11. data/lib/redis/cluster/option.rb +93 -0
  12. data/lib/redis/cluster/slot.rb +86 -0
  13. data/lib/redis/cluster/slot_loader.rb +49 -0
  14. data/lib/redis/cluster.rb +291 -0
  15. data/lib/redis/connection/command_helper.rb +5 -2
  16. data/lib/redis/connection/hiredis.rb +4 -3
  17. data/lib/redis/connection/registry.rb +2 -1
  18. data/lib/redis/connection/ruby.rb +125 -106
  19. data/lib/redis/connection/synchrony.rb +18 -5
  20. data/lib/redis/connection.rb +2 -0
  21. data/lib/redis/distributed.rb +995 -0
  22. data/lib/redis/errors.rb +48 -0
  23. data/lib/redis/hash_ring.rb +89 -0
  24. data/lib/redis/pipeline.rb +55 -9
  25. data/lib/redis/subscribe.rb +11 -12
  26. data/lib/redis/version.rb +3 -1
  27. data/lib/redis.rb +1433 -381
  28. metadata +34 -141
  29. data/.gitignore +0 -16
  30. data/.travis/Gemfile +0 -11
  31. data/.travis.yml +0 -71
  32. data/.yardopts +0 -3
  33. data/Gemfile +0 -3
  34. data/benchmarking/logging.rb +0 -71
  35. data/benchmarking/pipeline.rb +0 -51
  36. data/benchmarking/speed.rb +0 -21
  37. data/benchmarking/suite.rb +0 -24
  38. data/benchmarking/worker.rb +0 -71
  39. data/examples/basic.rb +0 -15
  40. data/examples/consistency.rb +0 -114
  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/sentinel.conf +0 -9
  45. data/examples/sentinel/start +0 -49
  46. data/examples/sentinel.rb +0 -41
  47. data/examples/sets.rb +0 -36
  48. data/examples/unicorn/config.ru +0 -3
  49. data/examples/unicorn/unicorn.rb +0 -20
  50. data/makefile +0 -42
  51. data/redis.gemspec +0 -40
  52. data/test/bitpos_test.rb +0 -63
  53. data/test/blocking_commands_test.rb +0 -183
  54. data/test/client_test.rb +0 -59
  55. data/test/command_map_test.rb +0 -28
  56. data/test/commands_on_hashes_test.rb +0 -174
  57. data/test/commands_on_hyper_log_log_test.rb +0 -70
  58. data/test/commands_on_lists_test.rb +0 -154
  59. data/test/commands_on_sets_test.rb +0 -208
  60. data/test/commands_on_sorted_sets_test.rb +0 -444
  61. data/test/commands_on_strings_test.rb +0 -338
  62. data/test/commands_on_value_types_test.rb +0 -246
  63. data/test/connection_handling_test.rb +0 -275
  64. data/test/db/.gitkeep +0 -0
  65. data/test/encoding_test.rb +0 -14
  66. data/test/error_replies_test.rb +0 -57
  67. data/test/fork_safety_test.rb +0 -60
  68. data/test/helper.rb +0 -179
  69. data/test/helper_test.rb +0 -22
  70. data/test/internals_test.rb +0 -435
  71. data/test/persistence_control_commands_test.rb +0 -24
  72. data/test/pipelining_commands_test.rb +0 -238
  73. data/test/publish_subscribe_test.rb +0 -280
  74. data/test/remote_server_control_commands_test.rb +0 -175
  75. data/test/scanning_test.rb +0 -407
  76. data/test/scripting_test.rb +0 -76
  77. data/test/sentinel_command_test.rb +0 -78
  78. data/test/sentinel_test.rb +0 -253
  79. data/test/sorting_test.rb +0 -57
  80. data/test/ssl_test.rb +0 -69
  81. data/test/support/connection/hiredis.rb +0 -1
  82. data/test/support/connection/ruby.rb +0 -1
  83. data/test/support/connection/synchrony.rb +0 -17
  84. data/test/support/redis_mock.rb +0 -130
  85. data/test/support/ssl/gen_certs.sh +0 -31
  86. data/test/support/ssl/trusted-ca.crt +0 -25
  87. data/test/support/ssl/trusted-ca.key +0 -27
  88. data/test/support/ssl/trusted-cert.crt +0 -81
  89. data/test/support/ssl/trusted-cert.key +0 -28
  90. data/test/support/ssl/untrusted-ca.crt +0 -26
  91. data/test/support/ssl/untrusted-ca.key +0 -27
  92. data/test/support/ssl/untrusted-cert.crt +0 -82
  93. data/test/support/ssl/untrusted-cert.key +0 -28
  94. data/test/support/wire/synchrony.rb +0 -24
  95. data/test/support/wire/thread.rb +0 -5
  96. data/test/synchrony_driver.rb +0 -85
  97. data/test/test.conf.erb +0 -9
  98. data/test/thread_safety_test.rb +0 -60
  99. data/test/transactions_test.rb +0 -262
  100. data/test/unknown_commands_test.rb +0 -12
  101. data/test/url_param_test.rb +0 -136
data/test/client_test.rb DELETED
@@ -1,59 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestClient < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_call
8
- result = r.call("PING")
9
- assert_equal result, "PONG"
10
- end
11
-
12
- def test_call_with_arguments
13
- result = r.call("SET", "foo", "bar")
14
- assert_equal result, "OK"
15
- end
16
-
17
- def test_call_integers
18
- result = r.call("INCR", "foo")
19
- assert_equal result, 1
20
- end
21
-
22
- def test_call_raise
23
- assert_raises(Redis::CommandError) do
24
- r.call("INCR")
25
- end
26
- end
27
-
28
- def test_queue_commit
29
- r.queue("SET", "foo", "bar")
30
- r.queue("GET", "foo")
31
- result = r.commit
32
-
33
- assert_equal result, ["OK", "bar"]
34
- end
35
-
36
- def test_commit_raise
37
- r.queue("SET", "foo", "bar")
38
- r.queue("INCR")
39
-
40
- assert_raise(Redis::CommandError) do
41
- r.commit
42
- end
43
- end
44
-
45
- def test_queue_after_error
46
- r.queue("SET", "foo", "bar")
47
- r.queue("INCR")
48
-
49
- assert_raise(Redis::CommandError) do
50
- r.commit
51
- end
52
-
53
- r.queue("SET", "foo", "bar")
54
- r.queue("INCR", "baz")
55
- result = r.commit
56
-
57
- assert_equal result, ["OK", 1]
58
- end
59
- end
@@ -1,28 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestCommandMap < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_override_existing_commands
8
- r.set("counter", 1)
9
-
10
- assert_equal 2, r.incr("counter")
11
-
12
- r._client.command_map[:incr] = :decr
13
-
14
- assert_equal 1, r.incr("counter")
15
- end
16
-
17
- def test_override_non_existing_commands
18
- r.set("key", "value")
19
-
20
- assert_raise Redis::CommandError do
21
- r.idontexist("key")
22
- end
23
-
24
- r._client.command_map[:idontexist] = :get
25
-
26
- assert_equal "value", r.idontexist("key")
27
- end
28
- end
@@ -1,174 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestCommandsOnHashes < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_hset_and_hget
8
- r.hset("foo", "f1", "s1")
9
-
10
- assert_equal "s1", r.hget("foo", "f1")
11
- end
12
-
13
- def test_hsetnx
14
- r.hset("foo", "f1", "s1")
15
- r.hsetnx("foo", "f1", "s2")
16
-
17
- assert_equal "s1", r.hget("foo", "f1")
18
-
19
- r.del("foo")
20
- r.hsetnx("foo", "f1", "s2")
21
-
22
- assert_equal "s2", r.hget("foo", "f1")
23
- end
24
-
25
- def test_hdel
26
- r.hset("foo", "f1", "s1")
27
-
28
- assert_equal "s1", r.hget("foo", "f1")
29
-
30
- assert_equal 1, r.hdel("foo", "f1")
31
-
32
- assert_equal nil, r.hget("foo", "f1")
33
- end
34
-
35
- def test_variadic_hdel
36
- target_version "2.3.9" do
37
- r.hset("foo", "f1", "s1")
38
- r.hset("foo", "f2", "s2")
39
-
40
- assert_equal "s1", r.hget("foo", "f1")
41
- assert_equal "s2", r.hget("foo", "f2")
42
-
43
- assert_equal 2, r.hdel("foo", ["f1", "f2"])
44
-
45
- assert_equal nil, r.hget("foo", "f1")
46
- assert_equal nil, r.hget("foo", "f2")
47
- end
48
- end
49
-
50
- def test_hexists
51
- assert_equal false, r.hexists("foo", "f1")
52
-
53
- r.hset("foo", "f1", "s1")
54
-
55
- assert r.hexists("foo", "f1")
56
- end
57
-
58
- def test_hlen
59
- assert_equal 0, r.hlen("foo")
60
-
61
- r.hset("foo", "f1", "s1")
62
-
63
- assert_equal 1, r.hlen("foo")
64
-
65
- r.hset("foo", "f2", "s2")
66
-
67
- assert_equal 2, r.hlen("foo")
68
- end
69
-
70
- def test_hkeys
71
- assert_equal [], r.hkeys("foo")
72
-
73
- r.hset("foo", "f1", "s1")
74
- r.hset("foo", "f2", "s2")
75
-
76
- assert_equal ["f1", "f2"], r.hkeys("foo")
77
- end
78
-
79
- def test_hvals
80
- assert_equal [], r.hvals("foo")
81
-
82
- r.hset("foo", "f1", "s1")
83
- r.hset("foo", "f2", "s2")
84
-
85
- assert_equal ["s1", "s2"], r.hvals("foo")
86
- end
87
-
88
- def test_hgetall
89
- assert({} == r.hgetall("foo"))
90
-
91
- r.hset("foo", "f1", "s1")
92
- r.hset("foo", "f2", "s2")
93
-
94
- assert({"f1" => "s1", "f2" => "s2"} == r.hgetall("foo"))
95
- end
96
-
97
- def test_hmset
98
- r.hmset("hash", "foo1", "bar1", "foo2", "bar2")
99
-
100
- assert_equal "bar1", r.hget("hash", "foo1")
101
- assert_equal "bar2", r.hget("hash", "foo2")
102
- end
103
-
104
- def test_hmset_with_invalid_arguments
105
- assert_raise(Redis::CommandError) do
106
- r.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3")
107
- end
108
- end
109
-
110
- def test_mapped_hmset
111
- r.mapped_hmset("foo", :f1 => "s1", :f2 => "s2")
112
-
113
- assert_equal "s1", r.hget("foo", "f1")
114
- assert_equal "s2", r.hget("foo", "f2")
115
- end
116
-
117
- def test_hmget
118
- r.hset("foo", "f1", "s1")
119
- r.hset("foo", "f2", "s2")
120
- r.hset("foo", "f3", "s3")
121
-
122
- assert_equal ["s2", "s3"], r.hmget("foo", "f2", "f3")
123
- end
124
-
125
- def test_hmget_mapped
126
- r.hset("foo", "f1", "s1")
127
- r.hset("foo", "f2", "s2")
128
- r.hset("foo", "f3", "s3")
129
-
130
- assert({"f1" => "s1"} == r.mapped_hmget("foo", "f1"))
131
- assert({"f1" => "s1", "f2" => "s2"} == r.mapped_hmget("foo", "f1", "f2"))
132
- end
133
-
134
- def test_hincrby
135
- r.hincrby("foo", "f1", 1)
136
-
137
- assert_equal "1", r.hget("foo", "f1")
138
-
139
- r.hincrby("foo", "f1", 2)
140
-
141
- assert_equal "3", r.hget("foo", "f1")
142
-
143
- r.hincrby("foo", "f1", -1)
144
-
145
- assert_equal "2", r.hget("foo", "f1")
146
- end
147
-
148
- def test_hincrbyfloat
149
- target_version "2.5.4" do
150
- r.hincrbyfloat("foo", "f1", 1.23)
151
-
152
- assert_equal "1.23", r.hget("foo", "f1")
153
-
154
- r.hincrbyfloat("foo", "f1", 0.77)
155
-
156
- assert_equal "2", r.hget("foo", "f1")
157
-
158
- r.hincrbyfloat("foo", "f1", -0.1)
159
-
160
- assert_equal "1.9", r.hget("foo", "f1")
161
- end
162
- end
163
-
164
- def test_mapped_hmget_in_a_pipeline_returns_hash
165
- r.hset("foo", "f1", "s1")
166
- r.hset("foo", "f2", "s2")
167
-
168
- result = r.pipelined do
169
- r.mapped_hmget("foo", "f1", "f2")
170
- end
171
-
172
- assert_equal result[0], { "f1" => "s1", "f2" => "s2" }
173
- end
174
- end
@@ -1,70 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestCommandsOnHyperLogLog < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_pfadd
8
- target_version "2.8.9" do
9
- assert_equal true, r.pfadd("foo", "s1")
10
- assert_equal true, r.pfadd("foo", "s2")
11
- assert_equal false, r.pfadd("foo", "s1")
12
-
13
- assert_equal 2, r.pfcount("foo")
14
- end
15
- end
16
-
17
- def test_variadic_pfadd
18
- target_version "2.8.9" do
19
- assert_equal true, r.pfadd("foo", ["s1", "s2"])
20
- assert_equal true, r.pfadd("foo", ["s1", "s2", "s3"])
21
-
22
- assert_equal 3, r.pfcount("foo")
23
- end
24
- end
25
-
26
- def test_pfcount
27
- target_version "2.8.9" do
28
- assert_equal 0, r.pfcount("foo")
29
-
30
- assert_equal true, r.pfadd("foo", "s1")
31
-
32
- assert_equal 1, r.pfcount("foo")
33
- end
34
- end
35
-
36
- def test_variadic_pfcount
37
- target_version "2.8.9" do
38
- assert_equal 0, r.pfcount(["{1}foo", "{1}bar"])
39
-
40
- assert_equal true, r.pfadd("{1}foo", "s1")
41
- assert_equal true, r.pfadd("{1}bar", "s1")
42
- assert_equal true, r.pfadd("{1}bar", "s2")
43
-
44
- assert_equal 2, r.pfcount("{1}foo", "{1}bar")
45
- end
46
- end
47
-
48
- def test_variadic_pfcount_expanded
49
- target_version "2.8.9" do
50
- assert_equal 0, r.pfcount("{1}foo", "{1}bar")
51
-
52
- assert_equal true, r.pfadd("{1}foo", "s1")
53
- assert_equal true, r.pfadd("{1}bar", "s1")
54
- assert_equal true, r.pfadd("{1}bar", "s2")
55
-
56
- assert_equal 2, r.pfcount("{1}foo", "{1}bar")
57
- end
58
- end
59
-
60
- def test_pfmerge
61
- target_version "2.8.9" do
62
- r.pfadd "foo", "s1"
63
- r.pfadd "bar", "s2"
64
-
65
- assert_equal true, r.pfmerge("res", "foo", "bar")
66
- assert_equal 2, r.pfcount("res")
67
- end
68
- end
69
-
70
- end
@@ -1,154 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestCommandsOnLists < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_lpush
8
- r.lpush "foo", "s1"
9
- r.lpush "foo", "s2"
10
-
11
- assert_equal 2, r.llen("foo")
12
- assert_equal "s2", r.lpop("foo")
13
- end
14
-
15
- def test_variadic_lpush
16
- target_version "2.3.9" do # 2.4-rc6
17
- assert_equal 3, r.lpush("foo", ["s1", "s2", "s3"])
18
- assert_equal 3, r.llen("foo")
19
- assert_equal "s3", r.lpop("foo")
20
- end
21
- end
22
-
23
- def test_lpushx
24
- r.lpushx "foo", "s1"
25
- r.lpush "foo", "s2"
26
- r.lpushx "foo", "s3"
27
-
28
- assert_equal 2, r.llen("foo")
29
- assert_equal ["s3", "s2"], r.lrange("foo", 0, -1)
30
- end
31
-
32
- def test_rpush
33
- r.rpush "foo", "s1"
34
- r.rpush "foo", "s2"
35
-
36
- assert_equal 2, r.llen("foo")
37
- assert_equal "s2", r.rpop("foo")
38
- end
39
-
40
- def test_variadic_rpush
41
- target_version "2.3.9" do # 2.4-rc6
42
- assert_equal 3, r.rpush("foo", ["s1", "s2", "s3"])
43
- assert_equal 3, r.llen("foo")
44
- assert_equal "s3", r.rpop("foo")
45
- end
46
- end
47
-
48
- def test_rpushx
49
- r.rpushx "foo", "s1"
50
- r.rpush "foo", "s2"
51
- r.rpushx "foo", "s3"
52
-
53
- assert_equal 2, r.llen("foo")
54
- assert_equal ["s2", "s3"], r.lrange("foo", 0, -1)
55
- end
56
-
57
- def test_llen
58
- r.rpush "foo", "s1"
59
- r.rpush "foo", "s2"
60
-
61
- assert_equal 2, r.llen("foo")
62
- end
63
-
64
- def test_lrange
65
- r.rpush "foo", "s1"
66
- r.rpush "foo", "s2"
67
- r.rpush "foo", "s3"
68
-
69
- assert_equal ["s2", "s3"], r.lrange("foo", 1, -1)
70
- assert_equal ["s1", "s2"], r.lrange("foo", 0, 1)
71
-
72
- assert_equal [], r.lrange("bar", 0, -1)
73
- end
74
-
75
- def test_ltrim
76
- r.rpush "foo", "s1"
77
- r.rpush "foo", "s2"
78
- r.rpush "foo", "s3"
79
-
80
- r.ltrim "foo", 0, 1
81
-
82
- assert_equal 2, r.llen("foo")
83
- assert_equal ["s1", "s2"], r.lrange("foo", 0, -1)
84
- end
85
-
86
- def test_lindex
87
- r.rpush "foo", "s1"
88
- r.rpush "foo", "s2"
89
-
90
- assert_equal "s1", r.lindex("foo", 0)
91
- assert_equal "s2", r.lindex("foo", 1)
92
- end
93
-
94
- def test_lset
95
- r.rpush "foo", "s1"
96
- r.rpush "foo", "s2"
97
-
98
- assert_equal "s2", r.lindex("foo", 1)
99
- assert r.lset("foo", 1, "s3")
100
- assert_equal "s3", r.lindex("foo", 1)
101
-
102
- assert_raise Redis::CommandError do
103
- r.lset("foo", 4, "s3")
104
- end
105
- end
106
-
107
- def test_lrem
108
- r.rpush "foo", "s1"
109
- r.rpush "foo", "s2"
110
-
111
- assert_equal 1, r.lrem("foo", 1, "s1")
112
- assert_equal ["s2"], r.lrange("foo", 0, -1)
113
- end
114
-
115
- def test_lpop
116
- r.rpush "foo", "s1"
117
- r.rpush "foo", "s2"
118
-
119
- assert_equal 2, r.llen("foo")
120
- assert_equal "s1", r.lpop("foo")
121
- assert_equal 1, r.llen("foo")
122
- end
123
-
124
- def test_rpop
125
- r.rpush "foo", "s1"
126
- r.rpush "foo", "s2"
127
-
128
- assert_equal 2, r.llen("foo")
129
- assert_equal "s2", r.rpop("foo")
130
- assert_equal 1, r.llen("foo")
131
- end
132
-
133
- def test_linsert
134
- r.rpush "foo", "s1"
135
- r.rpush "foo", "s3"
136
- r.linsert "foo", :before, "s3", "s2"
137
-
138
- assert_equal ["s1", "s2", "s3"], r.lrange("foo", 0, -1)
139
-
140
- assert_raise(Redis::CommandError) do
141
- r.linsert "foo", :anywhere, "s3", "s2"
142
- end
143
- end
144
-
145
- def test_rpoplpush
146
- r.rpush "foo", "s1"
147
- r.rpush "foo", "s2"
148
-
149
- assert_equal "s2", r.rpoplpush("foo", "bar")
150
- assert_equal ["s2"], r.lrange("bar", 0, -1)
151
- assert_equal "s1", r.rpoplpush("foo", "bar")
152
- assert_equal ["s1", "s2"], r.lrange("bar", 0, -1)
153
- end
154
- end
@@ -1,208 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestCommandsOnSets < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_sadd
8
- assert_equal true, r.sadd("foo", "s1")
9
- assert_equal true, r.sadd("foo", "s2")
10
- assert_equal false, r.sadd("foo", "s1")
11
-
12
- assert_equal ["s1", "s2"], r.smembers("foo").sort
13
- end
14
-
15
- def test_variadic_sadd
16
- target_version "2.3.9" do # 2.4-rc6
17
- assert_equal 2, r.sadd("foo", ["s1", "s2"])
18
- assert_equal 1, r.sadd("foo", ["s1", "s2", "s3"])
19
-
20
- assert_equal ["s1", "s2", "s3"], r.smembers("foo").sort
21
- end
22
- end
23
-
24
- def test_srem
25
- r.sadd("foo", "s1")
26
- r.sadd("foo", "s2")
27
-
28
- assert_equal true, r.srem("foo", "s1")
29
- assert_equal false, r.srem("foo", "s3")
30
-
31
- assert_equal ["s2"], r.smembers("foo")
32
- end
33
-
34
- def test_variadic_srem
35
- target_version "2.3.9" do # 2.4-rc6
36
- r.sadd("foo", "s1")
37
- r.sadd("foo", "s2")
38
- r.sadd("foo", "s3")
39
-
40
- assert_equal 1, r.srem("foo", ["s1", "aaa"])
41
- assert_equal 0, r.srem("foo", ["bbb", "ccc" "ddd"])
42
- assert_equal 1, r.srem("foo", ["eee", "s3"])
43
-
44
- assert_equal ["s2"], r.smembers("foo")
45
- end
46
- end
47
-
48
- def test_spop
49
- r.sadd "foo", "s1"
50
- r.sadd "foo", "s2"
51
-
52
- assert ["s1", "s2"].include?(r.spop("foo"))
53
- assert ["s1", "s2"].include?(r.spop("foo"))
54
- assert_equal nil, r.spop("foo")
55
- end
56
-
57
- def test_spop_with_positive_count
58
- target_version "3.2.0" do
59
- r.sadd "foo", "s1"
60
- r.sadd "foo", "s2"
61
- r.sadd "foo", "s3"
62
- r.sadd "foo", "s4"
63
-
64
- pops = r.spop("foo", 3)
65
-
66
- assert !(["s1", "s2", "s3", "s4"] & pops).empty?
67
- assert_equal 3, pops.size
68
- assert_equal 1, r.scard("foo")
69
- end
70
- end
71
-
72
- def test_scard
73
- assert_equal 0, r.scard("foo")
74
-
75
- r.sadd "foo", "s1"
76
-
77
- assert_equal 1, r.scard("foo")
78
-
79
- r.sadd "foo", "s2"
80
-
81
- assert_equal 2, r.scard("foo")
82
- end
83
-
84
- def test_sismember
85
- assert_equal false, r.sismember("foo", "s1")
86
-
87
- r.sadd "foo", "s1"
88
-
89
- assert_equal true, r.sismember("foo", "s1")
90
- assert_equal false, r.sismember("foo", "s2")
91
- end
92
-
93
- def test_smembers
94
- assert_equal [], r.smembers("foo")
95
-
96
- r.sadd "foo", "s1"
97
- r.sadd "foo", "s2"
98
-
99
- assert_equal ["s1", "s2"], r.smembers("foo").sort
100
- end
101
-
102
- def test_srandmember
103
- r.sadd "foo", "s1"
104
- r.sadd "foo", "s2"
105
-
106
- 4.times do
107
- assert ["s1", "s2"].include?(r.srandmember("foo"))
108
- end
109
-
110
- assert_equal 2, r.scard("foo")
111
- end
112
-
113
- def test_srandmember_with_positive_count
114
- r.sadd "foo", "s1"
115
- r.sadd "foo", "s2"
116
- r.sadd "foo", "s3"
117
- r.sadd "foo", "s4"
118
-
119
- 4.times do
120
- assert !(["s1", "s2", "s3", "s4"] & r.srandmember("foo", 3)).empty?
121
-
122
- assert_equal 3, r.srandmember("foo", 3).size
123
- end
124
-
125
- assert_equal 4, r.scard("foo")
126
- end
127
-
128
- def test_srandmember_with_negative_count
129
- r.sadd "foo", "s1"
130
- r.sadd "foo", "s2"
131
- r.sadd "foo", "s3"
132
- r.sadd "foo", "s4"
133
-
134
- 4.times do
135
- assert !(["s1", "s2", "s3", "s4"] & r.srandmember("foo", -6)).empty?
136
- assert_equal 6, r.srandmember("foo", -6).size
137
- end
138
-
139
- assert_equal 4, r.scard("foo")
140
- end
141
-
142
- def test_smove
143
- r.sadd "foo", "s1"
144
- r.sadd "bar", "s2"
145
-
146
- assert r.smove("foo", "bar", "s1")
147
- assert r.sismember("bar", "s1")
148
- end
149
-
150
- def test_sinter
151
- r.sadd "foo", "s1"
152
- r.sadd "foo", "s2"
153
- r.sadd "bar", "s2"
154
-
155
- assert_equal ["s2"], r.sinter("foo", "bar")
156
- end
157
-
158
- def test_sinterstore
159
- r.sadd "foo", "s1"
160
- r.sadd "foo", "s2"
161
- r.sadd "bar", "s2"
162
-
163
- r.sinterstore("baz", "foo", "bar")
164
-
165
- assert_equal ["s2"], r.smembers("baz")
166
- end
167
-
168
- def test_sunion
169
- r.sadd "foo", "s1"
170
- r.sadd "foo", "s2"
171
- r.sadd "bar", "s2"
172
- r.sadd "bar", "s3"
173
-
174
- assert_equal ["s1", "s2", "s3"], r.sunion("foo", "bar").sort
175
- end
176
-
177
- def test_sunionstore
178
- r.sadd "foo", "s1"
179
- r.sadd "foo", "s2"
180
- r.sadd "bar", "s2"
181
- r.sadd "bar", "s3"
182
-
183
- r.sunionstore("baz", "foo", "bar")
184
-
185
- assert_equal ["s1", "s2", "s3"], r.smembers("baz").sort
186
- end
187
-
188
- def test_sdiff
189
- r.sadd "foo", "s1"
190
- r.sadd "foo", "s2"
191
- r.sadd "bar", "s2"
192
- r.sadd "bar", "s3"
193
-
194
- assert_equal ["s1"], r.sdiff("foo", "bar")
195
- assert_equal ["s3"], r.sdiff("bar", "foo")
196
- end
197
-
198
- def test_sdiffstore
199
- r.sadd "foo", "s1"
200
- r.sadd "foo", "s2"
201
- r.sadd "bar", "s2"
202
- r.sadd "bar", "s3"
203
-
204
- r.sdiffstore("baz", "foo", "bar")
205
-
206
- assert_equal ["s1"], r.smembers("baz")
207
- end
208
- end