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
@@ -0,0 +1,214 @@
|
|
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 [Integer] The number of members that were successfully added
|
19
|
+
def sadd(key, *members)
|
20
|
+
members.flatten!(1)
|
21
|
+
send_command([:sadd, key].concat(members))
|
22
|
+
end
|
23
|
+
|
24
|
+
# Add one or more members to a set.
|
25
|
+
#
|
26
|
+
# @param [String] key
|
27
|
+
# @param [String, Array<String>] member one member, or array of members
|
28
|
+
# @return [Boolean] Wether at least one member was successfully added.
|
29
|
+
def sadd?(key, *members)
|
30
|
+
members.flatten!(1)
|
31
|
+
send_command([:sadd, key].concat(members), &Boolify)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Remove one or more members from a set.
|
35
|
+
#
|
36
|
+
# @param [String] key
|
37
|
+
# @param [String, Array<String>] member one member, or array of members
|
38
|
+
# @return [Integer] The number of members that were successfully removed
|
39
|
+
def srem(key, *members)
|
40
|
+
members.flatten!(1)
|
41
|
+
send_command([:srem, key].concat(members))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Remove one or more members from a set.
|
45
|
+
#
|
46
|
+
# @param [String] key
|
47
|
+
# @param [String, Array<String>] member one member, or array of members
|
48
|
+
# @return [Boolean] Wether at least one member was successfully removed.
|
49
|
+
def srem?(key, *members)
|
50
|
+
members.flatten!(1)
|
51
|
+
send_command([:srem, key].concat(members), &Boolify)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Remove and return one or more random member from a set.
|
55
|
+
#
|
56
|
+
# @param [String] key
|
57
|
+
# @return [String]
|
58
|
+
# @param [Integer] count
|
59
|
+
def spop(key, count = nil)
|
60
|
+
if count.nil?
|
61
|
+
send_command([:spop, key])
|
62
|
+
else
|
63
|
+
send_command([:spop, key, Integer(count)])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get one or more random members from a set.
|
68
|
+
#
|
69
|
+
# @param [String] key
|
70
|
+
# @param [Integer] count
|
71
|
+
# @return [String]
|
72
|
+
def srandmember(key, count = nil)
|
73
|
+
if count.nil?
|
74
|
+
send_command([:srandmember, key])
|
75
|
+
else
|
76
|
+
send_command([:srandmember, key, count])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Move a member from one set to another.
|
81
|
+
#
|
82
|
+
# @param [String] source source key
|
83
|
+
# @param [String] destination destination key
|
84
|
+
# @param [String] member member to move from `source` to `destination`
|
85
|
+
# @return [Boolean]
|
86
|
+
def smove(source, destination, member)
|
87
|
+
send_command([:smove, source, destination, member], &Boolify)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Determine if a given value is a member of a set.
|
91
|
+
#
|
92
|
+
# @param [String] key
|
93
|
+
# @param [String] member
|
94
|
+
# @return [Boolean]
|
95
|
+
def sismember(key, member)
|
96
|
+
send_command([:sismember, key, member], &Boolify)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Determine if multiple values are members of a set.
|
100
|
+
#
|
101
|
+
# @param [String] key
|
102
|
+
# @param [String, Array<String>] members
|
103
|
+
# @return [Array<Boolean>]
|
104
|
+
def smismember(key, *members)
|
105
|
+
members.flatten!(1)
|
106
|
+
send_command([:smismember, key].concat(members)) do |reply|
|
107
|
+
reply.map(&Boolify)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Get all the members in a set.
|
112
|
+
#
|
113
|
+
# @param [String] key
|
114
|
+
# @return [Array<String>]
|
115
|
+
def smembers(key)
|
116
|
+
send_command([:smembers, key])
|
117
|
+
end
|
118
|
+
|
119
|
+
# Subtract multiple sets.
|
120
|
+
#
|
121
|
+
# @param [String, Array<String>] keys keys pointing to sets to subtract
|
122
|
+
# @return [Array<String>] members in the difference
|
123
|
+
def sdiff(*keys)
|
124
|
+
keys.flatten!(1)
|
125
|
+
send_command([:sdiff].concat(keys))
|
126
|
+
end
|
127
|
+
|
128
|
+
# Subtract multiple sets and store the resulting set in a key.
|
129
|
+
#
|
130
|
+
# @param [String] destination destination key
|
131
|
+
# @param [String, Array<String>] keys keys pointing to sets to subtract
|
132
|
+
# @return [Integer] number of elements in the resulting set
|
133
|
+
def sdiffstore(destination, *keys)
|
134
|
+
keys.flatten!(1)
|
135
|
+
send_command([:sdiffstore, destination].concat(keys))
|
136
|
+
end
|
137
|
+
|
138
|
+
# Intersect multiple sets.
|
139
|
+
#
|
140
|
+
# @param [String, Array<String>] keys keys pointing to sets to intersect
|
141
|
+
# @return [Array<String>] members in the intersection
|
142
|
+
def sinter(*keys)
|
143
|
+
keys.flatten!(1)
|
144
|
+
send_command([:sinter].concat(keys))
|
145
|
+
end
|
146
|
+
|
147
|
+
# Intersect multiple sets and store the resulting set in a key.
|
148
|
+
#
|
149
|
+
# @param [String] destination destination key
|
150
|
+
# @param [String, Array<String>] keys keys pointing to sets to intersect
|
151
|
+
# @return [Integer] number of elements in the resulting set
|
152
|
+
def sinterstore(destination, *keys)
|
153
|
+
keys.flatten!(1)
|
154
|
+
send_command([:sinterstore, destination].concat(keys))
|
155
|
+
end
|
156
|
+
|
157
|
+
# Add multiple sets.
|
158
|
+
#
|
159
|
+
# @param [String, Array<String>] keys keys pointing to sets to unify
|
160
|
+
# @return [Array<String>] members in the union
|
161
|
+
def sunion(*keys)
|
162
|
+
keys.flatten!(1)
|
163
|
+
send_command([:sunion].concat(keys))
|
164
|
+
end
|
165
|
+
|
166
|
+
# Add multiple sets and store the resulting set in a key.
|
167
|
+
#
|
168
|
+
# @param [String] destination destination key
|
169
|
+
# @param [String, Array<String>] keys keys pointing to sets to unify
|
170
|
+
# @return [Integer] number of elements in the resulting set
|
171
|
+
def sunionstore(destination, *keys)
|
172
|
+
keys.flatten!(1)
|
173
|
+
send_command([:sunionstore, destination].concat(keys))
|
174
|
+
end
|
175
|
+
|
176
|
+
# Scan a set
|
177
|
+
#
|
178
|
+
# @example Retrieve the first batch of keys in a set
|
179
|
+
# redis.sscan("set", 0)
|
180
|
+
#
|
181
|
+
# @param [String, Integer] cursor the cursor of the iteration
|
182
|
+
# @param [Hash] options
|
183
|
+
# - `:match => String`: only return keys matching the pattern
|
184
|
+
# - `:count => Integer`: return count keys at most per iteration
|
185
|
+
#
|
186
|
+
# @return [String, Array<String>] the next cursor and all found members
|
187
|
+
def sscan(key, cursor, **options)
|
188
|
+
_scan(:sscan, cursor, [key], **options)
|
189
|
+
end
|
190
|
+
|
191
|
+
# Scan a set
|
192
|
+
#
|
193
|
+
# @example Retrieve all of the keys in a set
|
194
|
+
# redis.sscan_each("set").to_a
|
195
|
+
# # => ["key1", "key2", "key3"]
|
196
|
+
#
|
197
|
+
# @param [Hash] options
|
198
|
+
# - `:match => String`: only return keys matching the pattern
|
199
|
+
# - `:count => Integer`: return count keys at most per iteration
|
200
|
+
#
|
201
|
+
# @return [Enumerator] an enumerator for all keys in the set
|
202
|
+
def sscan_each(key, **options, &block)
|
203
|
+
return to_enum(:sscan_each, key, **options) unless block_given?
|
204
|
+
|
205
|
+
cursor = 0
|
206
|
+
loop do
|
207
|
+
cursor, keys = sscan(key, cursor, **options)
|
208
|
+
keys.each(&block)
|
209
|
+
break if cursor == "0"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|