redis 4.1.0.beta1 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -2
  3. data/README.md +45 -0
  4. data/lib/redis.rb +497 -20
  5. data/lib/redis/client.rb +14 -6
  6. data/lib/redis/cluster.rb +1 -0
  7. data/lib/redis/cluster/command_loader.rb +2 -0
  8. data/lib/redis/cluster/node_loader.rb +2 -0
  9. data/lib/redis/cluster/option.rb +1 -0
  10. data/lib/redis/cluster/slot_loader.rb +2 -0
  11. data/lib/redis/distributed.rb +3 -4
  12. data/lib/redis/version.rb +1 -1
  13. metadata +20 -243
  14. data/.gitignore +0 -19
  15. data/.travis.yml +0 -61
  16. data/.travis/Gemfile +0 -18
  17. data/.yardopts +0 -3
  18. data/Gemfile +0 -8
  19. data/benchmarking/logging.rb +0 -71
  20. data/benchmarking/pipeline.rb +0 -51
  21. data/benchmarking/speed.rb +0 -21
  22. data/benchmarking/suite.rb +0 -24
  23. data/benchmarking/worker.rb +0 -71
  24. data/bin/build +0 -71
  25. data/bors.toml +0 -14
  26. data/examples/basic.rb +0 -15
  27. data/examples/consistency.rb +0 -114
  28. data/examples/dist_redis.rb +0 -43
  29. data/examples/incr-decr.rb +0 -17
  30. data/examples/list.rb +0 -26
  31. data/examples/pubsub.rb +0 -37
  32. data/examples/sentinel.rb +0 -41
  33. data/examples/sentinel/start +0 -49
  34. data/examples/sets.rb +0 -36
  35. data/examples/unicorn/config.ru +0 -3
  36. data/examples/unicorn/unicorn.rb +0 -20
  37. data/makefile +0 -74
  38. data/redis.gemspec +0 -42
  39. data/test/bitpos_test.rb +0 -63
  40. data/test/blocking_commands_test.rb +0 -40
  41. data/test/client_test.rb +0 -76
  42. data/test/cluster_abnormal_state_test.rb +0 -38
  43. data/test/cluster_blocking_commands_test.rb +0 -15
  44. data/test/cluster_client_internals_test.rb +0 -77
  45. data/test/cluster_client_key_hash_tags_test.rb +0 -88
  46. data/test/cluster_client_options_test.rb +0 -147
  47. data/test/cluster_client_pipelining_test.rb +0 -59
  48. data/test/cluster_client_replicas_test.rb +0 -36
  49. data/test/cluster_client_slots_test.rb +0 -94
  50. data/test/cluster_client_transactions_test.rb +0 -71
  51. data/test/cluster_commands_on_cluster_test.rb +0 -165
  52. data/test/cluster_commands_on_connection_test.rb +0 -40
  53. data/test/cluster_commands_on_geo_test.rb +0 -74
  54. data/test/cluster_commands_on_hashes_test.rb +0 -11
  55. data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
  56. data/test/cluster_commands_on_keys_test.rb +0 -134
  57. data/test/cluster_commands_on_lists_test.rb +0 -15
  58. data/test/cluster_commands_on_pub_sub_test.rb +0 -101
  59. data/test/cluster_commands_on_scripting_test.rb +0 -56
  60. data/test/cluster_commands_on_server_test.rb +0 -221
  61. data/test/cluster_commands_on_sets_test.rb +0 -39
  62. data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
  63. data/test/cluster_commands_on_streams_test.rb +0 -196
  64. data/test/cluster_commands_on_strings_test.rb +0 -15
  65. data/test/cluster_commands_on_transactions_test.rb +0 -41
  66. data/test/cluster_commands_on_value_types_test.rb +0 -14
  67. data/test/command_map_test.rb +0 -28
  68. data/test/commands_on_geo_test.rb +0 -116
  69. data/test/commands_on_hashes_test.rb +0 -7
  70. data/test/commands_on_hyper_log_log_test.rb +0 -7
  71. data/test/commands_on_lists_test.rb +0 -7
  72. data/test/commands_on_sets_test.rb +0 -7
  73. data/test/commands_on_sorted_sets_test.rb +0 -7
  74. data/test/commands_on_strings_test.rb +0 -7
  75. data/test/commands_on_value_types_test.rb +0 -207
  76. data/test/connection_handling_test.rb +0 -275
  77. data/test/connection_test.rb +0 -57
  78. data/test/distributed_blocking_commands_test.rb +0 -52
  79. data/test/distributed_commands_on_hashes_test.rb +0 -21
  80. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
  81. data/test/distributed_commands_on_lists_test.rb +0 -19
  82. data/test/distributed_commands_on_sets_test.rb +0 -105
  83. data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
  84. data/test/distributed_commands_on_strings_test.rb +0 -79
  85. data/test/distributed_commands_on_value_types_test.rb +0 -129
  86. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  87. data/test/distributed_connection_handling_test.rb +0 -21
  88. data/test/distributed_internals_test.rb +0 -68
  89. data/test/distributed_key_tags_test.rb +0 -50
  90. data/test/distributed_persistence_control_commands_test.rb +0 -24
  91. data/test/distributed_publish_subscribe_test.rb +0 -90
  92. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  93. data/test/distributed_scripting_test.rb +0 -100
  94. data/test/distributed_sorting_test.rb +0 -18
  95. data/test/distributed_test.rb +0 -56
  96. data/test/distributed_transactions_test.rb +0 -30
  97. data/test/encoding_test.rb +0 -14
  98. data/test/error_replies_test.rb +0 -57
  99. data/test/fork_safety_test.rb +0 -60
  100. data/test/helper.rb +0 -344
  101. data/test/helper_test.rb +0 -22
  102. data/test/internals_test.rb +0 -395
  103. data/test/lint/blocking_commands.rb +0 -174
  104. data/test/lint/hashes.rb +0 -203
  105. data/test/lint/hyper_log_log.rb +0 -74
  106. data/test/lint/lists.rb +0 -159
  107. data/test/lint/sets.rb +0 -282
  108. data/test/lint/sorted_sets.rb +0 -497
  109. data/test/lint/strings.rb +0 -348
  110. data/test/lint/value_types.rb +0 -130
  111. data/test/persistence_control_commands_test.rb +0 -24
  112. data/test/pipelining_commands_test.rb +0 -246
  113. data/test/publish_subscribe_test.rb +0 -280
  114. data/test/remote_server_control_commands_test.rb +0 -175
  115. data/test/scanning_test.rb +0 -407
  116. data/test/scripting_test.rb +0 -76
  117. data/test/sentinel_command_test.rb +0 -78
  118. data/test/sentinel_test.rb +0 -253
  119. data/test/sorting_test.rb +0 -57
  120. data/test/ssl_test.rb +0 -69
  121. data/test/support/cluster/orchestrator.rb +0 -199
  122. data/test/support/connection/hiredis.rb +0 -1
  123. data/test/support/connection/ruby.rb +0 -1
  124. data/test/support/connection/synchrony.rb +0 -17
  125. data/test/support/redis_mock.rb +0 -130
  126. data/test/support/ssl/gen_certs.sh +0 -31
  127. data/test/support/ssl/trusted-ca.crt +0 -25
  128. data/test/support/ssl/trusted-ca.key +0 -27
  129. data/test/support/ssl/trusted-cert.crt +0 -81
  130. data/test/support/ssl/trusted-cert.key +0 -28
  131. data/test/support/ssl/untrusted-ca.crt +0 -26
  132. data/test/support/ssl/untrusted-ca.key +0 -27
  133. data/test/support/ssl/untrusted-cert.crt +0 -82
  134. data/test/support/ssl/untrusted-cert.key +0 -28
  135. data/test/support/wire/synchrony.rb +0 -24
  136. data/test/support/wire/thread.rb +0 -5
  137. data/test/synchrony_driver.rb +0 -85
  138. data/test/test.conf.erb +0 -9
  139. data/test/thread_safety_test.rb +0 -60
  140. data/test/transactions_test.rb +0 -272
  141. data/test/unknown_commands_test.rb +0 -12
  142. data/test/url_param_test.rb +0 -136
@@ -1,203 +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_splat_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_variadic_hdel
49
- target_version "2.3.9" do
50
- r.hset("foo", "f1", "s1")
51
- r.hset("foo", "f2", "s2")
52
-
53
- assert_equal "s1", r.hget("foo", "f1")
54
- assert_equal "s2", r.hget("foo", "f2")
55
-
56
- assert_equal 2, r.hdel("foo", ["f1", "f2"])
57
-
58
- assert_equal nil, r.hget("foo", "f1")
59
- assert_equal nil, r.hget("foo", "f2")
60
- end
61
- end
62
-
63
- def test_hexists
64
- assert_equal false, r.hexists("foo", "f1")
65
-
66
- r.hset("foo", "f1", "s1")
67
-
68
- assert r.hexists("foo", "f1")
69
- end
70
-
71
- def test_hlen
72
- assert_equal 0, r.hlen("foo")
73
-
74
- r.hset("foo", "f1", "s1")
75
-
76
- assert_equal 1, r.hlen("foo")
77
-
78
- r.hset("foo", "f2", "s2")
79
-
80
- assert_equal 2, r.hlen("foo")
81
- end
82
-
83
- def test_hkeys
84
- assert_equal [], r.hkeys("foo")
85
-
86
- r.hset("foo", "f1", "s1")
87
- r.hset("foo", "f2", "s2")
88
-
89
- assert_equal ["f1", "f2"], r.hkeys("foo")
90
- end
91
-
92
- def test_hvals
93
- assert_equal [], r.hvals("foo")
94
-
95
- r.hset("foo", "f1", "s1")
96
- r.hset("foo", "f2", "s2")
97
-
98
- assert_equal ["s1", "s2"], r.hvals("foo")
99
- end
100
-
101
- def test_hgetall
102
- assert({} == r.hgetall("foo"))
103
-
104
- r.hset("foo", "f1", "s1")
105
- r.hset("foo", "f2", "s2")
106
-
107
- assert({"f1" => "s1", "f2" => "s2"} == r.hgetall("foo"))
108
- end
109
-
110
- def test_hmset
111
- r.hmset("hash", "foo1", "bar1", "foo2", "bar2")
112
-
113
- assert_equal "bar1", r.hget("hash", "foo1")
114
- assert_equal "bar2", r.hget("hash", "foo2")
115
- end
116
-
117
- def test_hmset_with_invalid_arguments
118
- assert_raise(Redis::CommandError) do
119
- r.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3")
120
- end
121
- end
122
-
123
- def test_mapped_hmset
124
- r.mapped_hmset("foo", :f1 => "s1", :f2 => "s2")
125
-
126
- assert_equal "s1", r.hget("foo", "f1")
127
- assert_equal "s2", r.hget("foo", "f2")
128
- end
129
-
130
- def test_hmget
131
- r.hset("foo", "f1", "s1")
132
- r.hset("foo", "f2", "s2")
133
- r.hset("foo", "f3", "s3")
134
-
135
- assert_equal ["s2", "s3"], r.hmget("foo", "f2", "f3")
136
- end
137
-
138
- def test_hmget_mapped
139
- r.hset("foo", "f1", "s1")
140
- r.hset("foo", "f2", "s2")
141
- r.hset("foo", "f3", "s3")
142
-
143
- assert({"f1" => "s1"} == r.mapped_hmget("foo", "f1"))
144
- assert({"f1" => "s1", "f2" => "s2"} == r.mapped_hmget("foo", "f1", "f2"))
145
- end
146
-
147
- def test_mapped_hmget_in_a_pipeline_returns_hash
148
- r.hset("foo", "f1", "s1")
149
- r.hset("foo", "f2", "s2")
150
-
151
- result = r.pipelined do
152
- r.mapped_hmget("foo", "f1", "f2")
153
- end
154
-
155
- assert_equal result[0], { "f1" => "s1", "f2" => "s2" }
156
- end
157
-
158
- def test_hincrby
159
- r.hincrby("foo", "f1", 1)
160
-
161
- assert_equal "1", r.hget("foo", "f1")
162
-
163
- r.hincrby("foo", "f1", 2)
164
-
165
- assert_equal "3", r.hget("foo", "f1")
166
-
167
- r.hincrby("foo", "f1", -1)
168
-
169
- assert_equal "2", r.hget("foo", "f1")
170
- end
171
-
172
- def test_hincrbyfloat
173
- target_version "2.5.4" do
174
- r.hincrbyfloat("foo", "f1", 1.23)
175
-
176
- assert_equal "1.23", r.hget("foo", "f1")
177
-
178
- r.hincrbyfloat("foo", "f1", 0.77)
179
-
180
- assert_equal "2", r.hget("foo", "f1")
181
-
182
- r.hincrbyfloat("foo", "f1", -0.1)
183
-
184
- assert_equal "1.9", r.hget("foo", "f1")
185
- end
186
- end
187
-
188
- def test_hstrlen
189
- target_version('3.2.0') do
190
- redis.hmset('foo', 'f1', 'HelloWorld', 'f2', 99, 'f3', -256)
191
- assert_equal 10, r.hstrlen('foo', 'f1')
192
- assert_equal 2, r.hstrlen('foo', 'f2')
193
- assert_equal 4, r.hstrlen('foo', 'f3')
194
- end
195
- end
196
-
197
- def test_hscan
198
- redis.hmset('foo', 'f1', 'Jack', 'f2', 33)
199
- expected = ['0', [%w[f1 Jack], %w[f2 33]]]
200
- assert_equal expected, redis.hscan('foo', 0)
201
- end
202
- end
203
- end
@@ -1,74 +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
- def test_pfmerge
59
- target_version '2.8.9' do
60
- r.pfadd 'foo', 's1'
61
- r.pfadd 'bar', 's2'
62
-
63
- assert_equal true, r.pfmerge('res', 'foo', 'bar')
64
- assert_equal 2, r.pfcount('res')
65
- end
66
- end
67
-
68
- def test_variadic_pfmerge_expanded
69
- redis.pfadd('{1}foo', %w[foo bar zap a])
70
- redis.pfadd('{1}bar', %w[a b c foo])
71
- assert_equal true, redis.pfmerge('{1}baz', '{1}foo', '{1}bar')
72
- end
73
- end
74
- end
@@ -1,159 +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
-
143
- def test_rpoplpush
144
- r.rpush 'foo', 's1'
145
- r.rpush 'foo', 's2'
146
-
147
- assert_equal 's2', r.rpoplpush('foo', 'bar')
148
- assert_equal ['s2'], r.lrange('bar', 0, -1)
149
- assert_equal 's1', r.rpoplpush('foo', 'bar')
150
- assert_equal %w[s1 s2], r.lrange('bar', 0, -1)
151
- end
152
-
153
- def test_variadic_rpoplpush_expand
154
- redis.rpush('{1}foo', %w[a b c])
155
- redis.rpush('{1}bar', %w[d e f])
156
- assert_equal 'c', redis.rpoplpush('{1}foo', '{1}bar')
157
- end
158
- end
159
- end
@@ -1,282 +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
-
140
- def test_smove
141
- r.sadd 'foo', 's1'
142
- r.sadd 'bar', 's2'
143
-
144
- assert r.smove('foo', 'bar', 's1')
145
- assert r.sismember('bar', 's1')
146
- end
147
-
148
- def test_sinter
149
- r.sadd 'foo', 's1'
150
- r.sadd 'foo', 's2'
151
- r.sadd 'bar', 's2'
152
-
153
- assert_equal ['s2'], r.sinter('foo', 'bar')
154
- end
155
-
156
- def test_variadic_smove_expand
157
- r.sadd('{1}foo', 's1')
158
- r.sadd('{1}foo', 's2')
159
- r.sadd('{1}foo', 's3')
160
- r.sadd('{1}bar', 's3')
161
- r.sadd('{1}bar', 's4')
162
- r.sadd('{1}bar', 's5')
163
- assert_equal true, r.smove('{1}foo', '{1}bar', 's2')
164
- end
165
-
166
- def test_variadic_sinter_expand
167
- r.sadd('{1}foo', 's1')
168
- r.sadd('{1}foo', 's2')
169
- r.sadd('{1}foo', 's3')
170
- r.sadd('{1}bar', 's3')
171
- r.sadd('{1}bar', 's4')
172
- r.sadd('{1}bar', 's5')
173
- assert_equal %w[s3], r.sinter('{1}foo', '{1}bar')
174
- end
175
-
176
- def test_sinterstore
177
- r.sadd 'foo', 's1'
178
- r.sadd 'foo', 's2'
179
- r.sadd 'bar', 's2'
180
-
181
- r.sinterstore('baz', 'foo', 'bar')
182
-
183
- assert_equal ['s2'], r.smembers('baz')
184
- end
185
-
186
- def test_variadic_sinterstore_expand
187
- r.sadd('{1}foo', 's1')
188
- r.sadd('{1}foo', 's2')
189
- r.sadd('{1}foo', 's3')
190
- r.sadd('{1}bar', 's3')
191
- r.sadd('{1}bar', 's4')
192
- r.sadd('{1}bar', 's5')
193
- assert_equal 1, r.sinterstore('{1}baz', '{1}foo', '{1}bar')
194
- end
195
-
196
- def test_sunion
197
- r.sadd 'foo', 's1'
198
- r.sadd 'foo', 's2'
199
- r.sadd 'bar', 's2'
200
- r.sadd 'bar', 's3'
201
-
202
- assert_equal %w[s1 s2 s3], r.sunion('foo', 'bar').sort
203
- end
204
-
205
- def test_variadic_sunion_expand
206
- r.sadd('{1}foo', 's1')
207
- r.sadd('{1}foo', 's2')
208
- r.sadd('{1}foo', 's3')
209
- r.sadd('{1}bar', 's3')
210
- r.sadd('{1}bar', 's4')
211
- r.sadd('{1}bar', 's5')
212
- assert_equal %w[s1 s2 s3 s4 s5], r.sunion('{1}foo', '{1}bar').sort
213
- end
214
-
215
- def test_sunionstore
216
- r.sadd 'foo', 's1'
217
- r.sadd 'foo', 's2'
218
- r.sadd 'bar', 's2'
219
- r.sadd 'bar', 's3'
220
-
221
- r.sunionstore('baz', 'foo', 'bar')
222
-
223
- assert_equal %w[s1 s2 s3], r.smembers('baz').sort
224
- end
225
-
226
- def test_variadic_sunionstore_expand
227
- r.sadd('{1}foo', 's1')
228
- r.sadd('{1}foo', 's2')
229
- r.sadd('{1}foo', 's3')
230
- r.sadd('{1}bar', 's3')
231
- r.sadd('{1}bar', 's4')
232
- r.sadd('{1}bar', 's5')
233
- assert_equal 5, r.sunionstore('{1}baz', '{1}foo', '{1}bar')
234
- end
235
-
236
- def test_sdiff
237
- r.sadd 'foo', 's1'
238
- r.sadd 'foo', 's2'
239
- r.sadd 'bar', 's2'
240
- r.sadd 'bar', 's3'
241
-
242
- assert_equal ['s1'], r.sdiff('foo', 'bar')
243
- assert_equal ['s3'], r.sdiff('bar', 'foo')
244
- end
245
-
246
- def test_variadic_sdiff_expand
247
- r.sadd('{1}foo', 's1')
248
- r.sadd('{1}foo', 's2')
249
- r.sadd('{1}foo', 's3')
250
- r.sadd('{1}bar', 's3')
251
- r.sadd('{1}bar', 's4')
252
- r.sadd('{1}bar', 's5')
253
- assert_equal %w[s1 s2], r.sdiff('{1}foo', '{1}bar').sort
254
- end
255
-
256
- def test_sdiffstore
257
- r.sadd 'foo', 's1'
258
- r.sadd 'foo', 's2'
259
- r.sadd 'bar', 's2'
260
- r.sadd 'bar', 's3'
261
-
262
- r.sdiffstore('baz', 'foo', 'bar')
263
-
264
- assert_equal ['s1'], r.smembers('baz')
265
- end
266
-
267
- def test_variadic_sdiffstore_expand
268
- r.sadd('{1}foo', 's1')
269
- r.sadd('{1}foo', 's2')
270
- r.sadd('{1}foo', 's3')
271
- r.sadd('{1}bar', 's3')
272
- r.sadd('{1}bar', 's4')
273
- r.sadd('{1}bar', 's5')
274
- assert_equal 2, r.sdiffstore('{1}baz', '{1}foo', '{1}bar')
275
- end
276
-
277
- def test_sscan
278
- r.sadd('foo', %w[1 2 3 foo foobar feelsgood])
279
- assert_equal %w[0 feelsgood foo foobar], r.sscan('foo', 0, match: 'f*').flatten.sort
280
- end
281
- end
282
- end