redis 3.3.5 → 4.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +236 -2
- data/README.md +169 -89
- data/lib/redis/client.rb +176 -108
- data/lib/redis/cluster/command.rb +79 -0
- data/lib/redis/cluster/command_loader.rb +33 -0
- data/lib/redis/cluster/key_slot_converter.rb +72 -0
- data/lib/redis/cluster/node.rb +120 -0
- data/lib/redis/cluster/node_key.rb +31 -0
- data/lib/redis/cluster/node_loader.rb +34 -0
- data/lib/redis/cluster/option.rb +100 -0
- data/lib/redis/cluster/slot.rb +86 -0
- data/lib/redis/cluster/slot_loader.rb +46 -0
- data/lib/redis/cluster.rb +315 -0
- data/lib/redis/commands/bitmaps.rb +63 -0
- data/lib/redis/commands/cluster.rb +45 -0
- data/lib/redis/commands/connection.rb +58 -0
- data/lib/redis/commands/geo.rb +84 -0
- data/lib/redis/commands/hashes.rb +251 -0
- data/lib/redis/commands/hyper_log_log.rb +37 -0
- data/lib/redis/commands/keys.rb +455 -0
- data/lib/redis/commands/lists.rb +290 -0
- data/lib/redis/commands/pubsub.rb +72 -0
- data/lib/redis/commands/scripting.rb +114 -0
- data/lib/redis/commands/server.rb +188 -0
- data/lib/redis/commands/sets.rb +223 -0
- data/lib/redis/commands/sorted_sets.rb +812 -0
- data/lib/redis/commands/streams.rb +382 -0
- data/lib/redis/commands/strings.rb +313 -0
- data/lib/redis/commands/transactions.rb +139 -0
- data/lib/redis/commands.rb +240 -0
- data/lib/redis/connection/command_helper.rb +7 -10
- data/lib/redis/connection/hiredis.rb +5 -3
- data/lib/redis/connection/registry.rb +2 -1
- data/lib/redis/connection/ruby.rb +136 -128
- data/lib/redis/connection/synchrony.rb +24 -9
- data/lib/redis/connection.rb +3 -1
- data/lib/redis/distributed.rb +255 -85
- data/lib/redis/errors.rb +57 -0
- data/lib/redis/hash_ring.rb +30 -73
- data/lib/redis/pipeline.rb +178 -13
- data/lib/redis/subscribe.rb +11 -12
- data/lib/redis/version.rb +3 -1
- data/lib/redis.rb +174 -2661
- metadata +66 -202
- 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/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/connection_test.rb +0 -57
- 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 -417
- 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
@@ -0,0 +1,223 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Redis
|
4
|
+
module Commands
|
5
|
+
module Sets
|
6
|
+
# Get the number of members in a set.
|
7
|
+
#
|
8
|
+
# @param [String] key
|
9
|
+
# @return [Integer]
|
10
|
+
def scard(key)
|
11
|
+
send_command([:scard, key])
|
12
|
+
end
|
13
|
+
|
14
|
+
# Add one or more members to a set.
|
15
|
+
#
|
16
|
+
# @param [String] key
|
17
|
+
# @param [String, Array<String>] member one member, or array of members
|
18
|
+
# @return [Boolean, Integer] `Boolean` when a single member is specified,
|
19
|
+
# holding whether or not adding the member succeeded, or `Integer` when an
|
20
|
+
# array of members is specified, holding the number of members that were
|
21
|
+
# successfully added
|
22
|
+
def sadd(key, member)
|
23
|
+
block = if Redis.sadd_returns_boolean && !member.is_a?(Array)
|
24
|
+
::Redis.deprecate!(
|
25
|
+
"Redis#sadd will always return an Integer in Redis 5.0.0. Use Redis#sadd? instead." \
|
26
|
+
"(called from: #{caller(1, 1).first})"
|
27
|
+
)
|
28
|
+
Boolify
|
29
|
+
end
|
30
|
+
send_command([:sadd, key, member], &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Add one or more members to a set.
|
34
|
+
#
|
35
|
+
# @param [String] key
|
36
|
+
# @param [String, Array<String>] member one member, or array of members
|
37
|
+
# @return [Boolean] Whether or not at least one member was added.
|
38
|
+
def sadd?(key, member)
|
39
|
+
send_command([:sadd, key, member], &Boolify)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Remove one or more members from a set.
|
43
|
+
#
|
44
|
+
# @param [String] key
|
45
|
+
# @param [String, Array<String>] member one member, or array of members
|
46
|
+
# @return [Boolean, Integer] `Boolean` when a single member is specified,
|
47
|
+
# holding whether or not removing the member succeeded, or `Integer` when an
|
48
|
+
# array of members is specified, holding the number of members that were
|
49
|
+
# successfully removed
|
50
|
+
def srem(key, member)
|
51
|
+
block = if Redis.sadd_returns_boolean && !member.is_a?(Array)
|
52
|
+
::Redis.deprecate!(
|
53
|
+
"Redis#srem will always return an Integer in Redis 5.0.0. Use Redis#srem? instead." \
|
54
|
+
"(called from: #{caller(1, 1).first})"
|
55
|
+
)
|
56
|
+
Boolify
|
57
|
+
end
|
58
|
+
send_command([:srem, key, member], &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Remove one or more members from a set.
|
62
|
+
#
|
63
|
+
# @param [String] key
|
64
|
+
# @param [String, Array<String>] member one member, or array of members
|
65
|
+
# @return [Boolean] `Boolean` Whether or not a member was removed.
|
66
|
+
def srem?(key, member)
|
67
|
+
send_command([:srem, key, member], &Boolify)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Remove and return one or more random member from a set.
|
71
|
+
#
|
72
|
+
# @param [String] key
|
73
|
+
# @return [String]
|
74
|
+
# @param [Integer] count
|
75
|
+
def spop(key, count = nil)
|
76
|
+
if count.nil?
|
77
|
+
send_command([:spop, key])
|
78
|
+
else
|
79
|
+
send_command([:spop, key, count])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Get one or more random members from a set.
|
84
|
+
#
|
85
|
+
# @param [String] key
|
86
|
+
# @param [Integer] count
|
87
|
+
# @return [String]
|
88
|
+
def srandmember(key, count = nil)
|
89
|
+
if count.nil?
|
90
|
+
send_command([:srandmember, key])
|
91
|
+
else
|
92
|
+
send_command([:srandmember, key, count])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Move a member from one set to another.
|
97
|
+
#
|
98
|
+
# @param [String] source source key
|
99
|
+
# @param [String] destination destination key
|
100
|
+
# @param [String] member member to move from `source` to `destination`
|
101
|
+
# @return [Boolean]
|
102
|
+
def smove(source, destination, member)
|
103
|
+
send_command([:smove, source, destination, member], &Boolify)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Determine if a given value is a member of a set.
|
107
|
+
#
|
108
|
+
# @param [String] key
|
109
|
+
# @param [String] member
|
110
|
+
# @return [Boolean]
|
111
|
+
def sismember(key, member)
|
112
|
+
send_command([:sismember, key, member], &Boolify)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Determine if multiple values are members of a set.
|
116
|
+
#
|
117
|
+
# @param [String] key
|
118
|
+
# @param [String, Array<String>] members
|
119
|
+
# @return [Array<Boolean>]
|
120
|
+
def smismember(key, *members)
|
121
|
+
send_command([:smismember, key, *members]) do |reply|
|
122
|
+
reply.map(&Boolify)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Get all the members in a set.
|
127
|
+
#
|
128
|
+
# @param [String] key
|
129
|
+
# @return [Array<String>]
|
130
|
+
def smembers(key)
|
131
|
+
send_command([:smembers, key])
|
132
|
+
end
|
133
|
+
|
134
|
+
# Subtract multiple sets.
|
135
|
+
#
|
136
|
+
# @param [String, Array<String>] keys keys pointing to sets to subtract
|
137
|
+
# @return [Array<String>] members in the difference
|
138
|
+
def sdiff(*keys)
|
139
|
+
send_command([:sdiff, *keys])
|
140
|
+
end
|
141
|
+
|
142
|
+
# Subtract multiple sets and store the resulting set in a key.
|
143
|
+
#
|
144
|
+
# @param [String] destination destination key
|
145
|
+
# @param [String, Array<String>] keys keys pointing to sets to subtract
|
146
|
+
# @return [Integer] number of elements in the resulting set
|
147
|
+
def sdiffstore(destination, *keys)
|
148
|
+
send_command([:sdiffstore, destination, *keys])
|
149
|
+
end
|
150
|
+
|
151
|
+
# Intersect multiple sets.
|
152
|
+
#
|
153
|
+
# @param [String, Array<String>] keys keys pointing to sets to intersect
|
154
|
+
# @return [Array<String>] members in the intersection
|
155
|
+
def sinter(*keys)
|
156
|
+
send_command([:sinter, *keys])
|
157
|
+
end
|
158
|
+
|
159
|
+
# Intersect multiple sets and store the resulting set in a key.
|
160
|
+
#
|
161
|
+
# @param [String] destination destination key
|
162
|
+
# @param [String, Array<String>] keys keys pointing to sets to intersect
|
163
|
+
# @return [Integer] number of elements in the resulting set
|
164
|
+
def sinterstore(destination, *keys)
|
165
|
+
send_command([:sinterstore, destination, *keys])
|
166
|
+
end
|
167
|
+
|
168
|
+
# Add multiple sets.
|
169
|
+
#
|
170
|
+
# @param [String, Array<String>] keys keys pointing to sets to unify
|
171
|
+
# @return [Array<String>] members in the union
|
172
|
+
def sunion(*keys)
|
173
|
+
send_command([:sunion, *keys])
|
174
|
+
end
|
175
|
+
|
176
|
+
# Add multiple sets and store the resulting set in a key.
|
177
|
+
#
|
178
|
+
# @param [String] destination destination key
|
179
|
+
# @param [String, Array<String>] keys keys pointing to sets to unify
|
180
|
+
# @return [Integer] number of elements in the resulting set
|
181
|
+
def sunionstore(destination, *keys)
|
182
|
+
send_command([:sunionstore, destination, *keys])
|
183
|
+
end
|
184
|
+
|
185
|
+
# Scan a set
|
186
|
+
#
|
187
|
+
# @example Retrieve the first batch of keys in a set
|
188
|
+
# redis.sscan("set", 0)
|
189
|
+
#
|
190
|
+
# @param [String, Integer] cursor the cursor of the iteration
|
191
|
+
# @param [Hash] options
|
192
|
+
# - `:match => String`: only return keys matching the pattern
|
193
|
+
# - `:count => Integer`: return count keys at most per iteration
|
194
|
+
#
|
195
|
+
# @return [String, Array<String>] the next cursor and all found members
|
196
|
+
def sscan(key, cursor, **options)
|
197
|
+
_scan(:sscan, cursor, [key], **options)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Scan a set
|
201
|
+
#
|
202
|
+
# @example Retrieve all of the keys in a set
|
203
|
+
# redis.sscan_each("set").to_a
|
204
|
+
# # => ["key1", "key2", "key3"]
|
205
|
+
#
|
206
|
+
# @param [Hash] options
|
207
|
+
# - `:match => String`: only return keys matching the pattern
|
208
|
+
# - `:count => Integer`: return count keys at most per iteration
|
209
|
+
#
|
210
|
+
# @return [Enumerator] an enumerator for all keys in the set
|
211
|
+
def sscan_each(key, **options, &block)
|
212
|
+
return to_enum(:sscan_each, key, **options) unless block_given?
|
213
|
+
|
214
|
+
cursor = 0
|
215
|
+
loop do
|
216
|
+
cursor, keys = sscan(key, cursor, **options)
|
217
|
+
keys.each(&block)
|
218
|
+
break if cursor == "0"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|