Module: Redis::Commands::Sets
- Included in:
- Redis::Commands
- Defined in:
- lib/redis/commands/sets.rb
Instance Method Summary collapse
-
#sadd(key, member) ⇒ Boolean, Integer
Add one or more members to a set.
-
#scard(key) ⇒ Integer
Get the number of members in a set.
-
#sdiff(*keys) ⇒ Array<String>
Subtract multiple sets.
-
#sdiffstore(destination, *keys) ⇒ Integer
Subtract multiple sets and store the resulting set in a key.
-
#sinter(*keys) ⇒ Array<String>
Intersect multiple sets.
-
#sinterstore(destination, *keys) ⇒ Integer
Intersect multiple sets and store the resulting set in a key.
-
#sismember(key, member) ⇒ Boolean
Determine if a given value is a member of a set.
-
#smembers(key) ⇒ Array<String>
Get all the members in a set.
-
#smismember(key, *members) ⇒ Array<Boolean>
Determine if multiple values are members of a set.
-
#smove(source, destination, member) ⇒ Boolean
Move a member from one set to another.
-
#spop(key, count = nil) ⇒ String
Remove and return one or more random member from a set.
-
#srandmember(key, count = nil) ⇒ String
Get one or more random members from a set.
-
#srem(key, member) ⇒ Boolean, Integer
Remove one or more members from a set.
-
#sscan(key, cursor, **options) ⇒ String+
Scan a set.
-
#sscan_each(key, **options, &block) ⇒ Enumerator
Scan a set.
-
#sunion(*keys) ⇒ Array<String>
Add multiple sets.
-
#sunionstore(destination, *keys) ⇒ Integer
Add multiple sets and store the resulting set in a key.
Instance Method Details
#sadd(key, member) ⇒ Boolean, Integer
Add one or more members to a set.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/redis/commands/sets.rb', line 22 def sadd(key, member) send_command([:sadd, key, member]) do |reply| if member.is_a? Array # Variadic: return integer reply else # Single argument: return boolean Boolify.call(reply) end end end |
#scard(key) ⇒ Integer
Get the number of members in a set.
10 11 12 |
# File 'lib/redis/commands/sets.rb', line 10 def scard(key) send_command([:scard, key]) end |
#sdiff(*keys) ⇒ Array<String>
Subtract multiple sets.
122 123 124 |
# File 'lib/redis/commands/sets.rb', line 122 def sdiff(*keys) send_command([:sdiff, *keys]) end |
#sdiffstore(destination, *keys) ⇒ Integer
Subtract multiple sets and store the resulting set in a key.
131 132 133 |
# File 'lib/redis/commands/sets.rb', line 131 def sdiffstore(destination, *keys) send_command([:sdiffstore, destination, *keys]) end |
#sinter(*keys) ⇒ Array<String>
Intersect multiple sets.
139 140 141 |
# File 'lib/redis/commands/sets.rb', line 139 def sinter(*keys) send_command([:sinter, *keys]) end |
#sinterstore(destination, *keys) ⇒ Integer
Intersect multiple sets and store the resulting set in a key.
148 149 150 |
# File 'lib/redis/commands/sets.rb', line 148 def sinterstore(destination, *keys) send_command([:sinterstore, destination, *keys]) end |
#sismember(key, member) ⇒ Boolean
Determine if a given value is a member of a set.
95 96 97 |
# File 'lib/redis/commands/sets.rb', line 95 def sismember(key, member) send_command([:sismember, key, member], &Boolify) end |
#smembers(key) ⇒ Array<String>
Get all the members in a set.
114 115 116 |
# File 'lib/redis/commands/sets.rb', line 114 def smembers(key) send_command([:smembers, key]) end |
#smismember(key, *members) ⇒ Array<Boolean>
Determine if multiple values are members of a set.
104 105 106 107 108 |
# File 'lib/redis/commands/sets.rb', line 104 def smismember(key, *members) send_command([:smismember, key, *members]) do |reply| reply.map(&Boolify) end end |
#smove(source, destination, member) ⇒ Boolean
Move a member from one set to another.
86 87 88 |
# File 'lib/redis/commands/sets.rb', line 86 def smove(source, destination, member) send_command([:smove, source, destination, member], &Boolify) end |
#spop(key, count = nil) ⇒ String
Remove and return one or more random member from a set.
59 60 61 62 63 64 65 |
# File 'lib/redis/commands/sets.rb', line 59 def spop(key, count = nil) if count.nil? send_command([:spop, key]) else send_command([:spop, key, count]) end end |
#srandmember(key, count = nil) ⇒ String
Get one or more random members from a set.
72 73 74 75 76 77 78 |
# File 'lib/redis/commands/sets.rb', line 72 def srandmember(key, count = nil) if count.nil? send_command([:srandmember, key]) else send_command([:srandmember, key, count]) end end |
#srem(key, member) ⇒ Boolean, Integer
Remove one or more members from a set.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/redis/commands/sets.rb', line 42 def srem(key, member) send_command([:srem, key, member]) do |reply| if member.is_a? Array # Variadic: return integer reply else # Single argument: return boolean Boolify.call(reply) end end end |
#sscan(key, cursor, **options) ⇒ String+
Scan a set
180 181 182 |
# File 'lib/redis/commands/sets.rb', line 180 def sscan(key, cursor, **) _scan(:sscan, cursor, [key], **) end |
#sscan_each(key, **options, &block) ⇒ Enumerator
Scan a set
195 196 197 198 199 200 201 202 203 204 |
# File 'lib/redis/commands/sets.rb', line 195 def sscan_each(key, **, &block) return to_enum(:sscan_each, key, **) unless block_given? cursor = 0 loop do cursor, keys = sscan(key, cursor, **) keys.each(&block) break if cursor == "0" end end |
#sunion(*keys) ⇒ Array<String>
Add multiple sets.
156 157 158 |
# File 'lib/redis/commands/sets.rb', line 156 def sunion(*keys) send_command([:sunion, *keys]) end |
#sunionstore(destination, *keys) ⇒ Integer
Add multiple sets and store the resulting set in a key.
165 166 167 |
# File 'lib/redis/commands/sets.rb', line 165 def sunionstore(destination, *keys) send_command([:sunionstore, destination, *keys]) end |