Module: Valkey::Commands::SetCommands
- Included in:
- Valkey::Commands
- Defined in:
- lib/valkey/commands/set_commands.rb
Overview
this module contains commands related to set data type.
Instance Method Summary collapse
-
#sadd(key, *members) ⇒ Integer
Add one or more members to a set.
-
#sadd?(key, *members) ⇒ Boolean
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, *members) ⇒ Integer
Remove one or more members from a set.
-
#srem?(key, *members) ⇒ Boolean
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, *members) ⇒ Integer
Add one or more members to a set.
23 24 25 26 |
# File 'lib/valkey/commands/set_commands.rb', line 23 def sadd(key, *members) members.flatten!(1) send_command(RequestType::SADD, [key].concat(members)) end |
#sadd?(key, *members) ⇒ Boolean
Add one or more members to a set.
33 34 35 36 |
# File 'lib/valkey/commands/set_commands.rb', line 33 def sadd?(key, *members) members.flatten!(1) send_command(RequestType::SADD, [key].concat(members), &Utils::Boolify) end |
#scard(key) ⇒ Integer
Get the number of members in a set.
14 15 16 |
# File 'lib/valkey/commands/set_commands.rb', line 14 def scard(key) send_command(RequestType::SCARD, [key]) end |
#sdiff(*keys) ⇒ Array<String>
Subtract multiple sets.
125 126 127 128 |
# File 'lib/valkey/commands/set_commands.rb', line 125 def sdiff(*keys) keys.flatten!(1) send_command(RequestType::SDIFF, keys) end |
#sdiffstore(destination, *keys) ⇒ Integer
Subtract multiple sets and store the resulting set in a key.
135 136 137 138 |
# File 'lib/valkey/commands/set_commands.rb', line 135 def sdiffstore(destination, *keys) keys.flatten!(1) send_command(RequestType::SDIFF_STORE, [destination].concat(keys)) end |
#sinter(*keys) ⇒ Array<String>
Intersect multiple sets.
144 145 146 147 |
# File 'lib/valkey/commands/set_commands.rb', line 144 def sinter(*keys) keys.flatten!(1) send_command(RequestType::SINTER, keys) end |
#sinterstore(destination, *keys) ⇒ Integer
Intersect multiple sets and store the resulting set in a key.
154 155 156 157 |
# File 'lib/valkey/commands/set_commands.rb', line 154 def sinterstore(destination, *keys) keys.flatten!(1) send_command(RequestType::SINTER_STORE, [destination].concat(keys)) end |
#sismember(key, member) ⇒ Boolean
Determine if a given value is a member of a set.
99 100 101 |
# File 'lib/valkey/commands/set_commands.rb', line 99 def sismember(key, member) send_command(RequestType::SISMEMBER, [key, member]) end |
#smembers(key) ⇒ Array<String>
Get all the members in a set.
117 118 119 |
# File 'lib/valkey/commands/set_commands.rb', line 117 def smembers(key) send_command(RequestType::SMEMBERS, [key]) end |
#smismember(key, *members) ⇒ Array<Boolean>
Determine if multiple values are members of a set.
108 109 110 111 |
# File 'lib/valkey/commands/set_commands.rb', line 108 def smismember(key, *members) members.flatten!(1) send_command(RequestType::SMISMEMBER, [key].concat(members)) end |
#smove(source, destination, member) ⇒ Boolean
Move a member from one set to another.
90 91 92 |
# File 'lib/valkey/commands/set_commands.rb', line 90 def smove(source, destination, member) send_command(RequestType::S_MOVE, [source, destination, member]) end |
#spop(key, count = nil) ⇒ String
Remove and return one or more random member from a set.
63 64 65 66 67 68 69 |
# File 'lib/valkey/commands/set_commands.rb', line 63 def spop(key, count = nil) if count.nil? send_command(RequestType::S_POP, [key]) else send_command(RequestType::S_POP, [key, Integer(count)]) end end |
#srandmember(key, count = nil) ⇒ String
Get one or more random members from a set.
76 77 78 79 80 81 82 |
# File 'lib/valkey/commands/set_commands.rb', line 76 def srandmember(key, count = nil) if count.nil? send_command(RequestType::S_RAND_MEMBER, [key]) else send_command(RequestType::S_RAND_MEMBER, [key, count]) end end |
#srem(key, *members) ⇒ Integer
Remove one or more members from a set.
43 44 45 46 |
# File 'lib/valkey/commands/set_commands.rb', line 43 def srem(key, *members) members.flatten!(1) send_command(RequestType::S_REM, [key].concat(members)) end |
#srem?(key, *members) ⇒ Boolean
Remove one or more members from a set.
53 54 55 56 |
# File 'lib/valkey/commands/set_commands.rb', line 53 def srem?(key, *members) members.flatten!(1) send_command(RequestType::S_REM, [key].concat(members), &Utils::Boolify) end |
#sscan(key, cursor, **options) ⇒ String+
Scan a set
See the [Valkey Server SSCAN documentation](valkey.io/commands/sscan/) for further details
191 192 193 |
# File 'lib/valkey/commands/set_commands.rb', line 191 def sscan(key, cursor, **) _scan(RequestType::S_SCAN, cursor, [key], **) end |
#sscan_each(key, **options, &block) ⇒ Enumerator
Scan a set
See the [Valkey Server SSCAN documentation](valkey.io/commands/sscan/) for further details
208 209 210 211 212 213 214 215 216 217 |
# File 'lib/valkey/commands/set_commands.rb', line 208 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.
163 164 165 166 |
# File 'lib/valkey/commands/set_commands.rb', line 163 def sunion(*keys) keys.flatten!(1) send_command(RequestType::S_UNION, keys) end |
#sunionstore(destination, *keys) ⇒ Integer
Add multiple sets and store the resulting set in a key.
173 174 175 176 |
# File 'lib/valkey/commands/set_commands.rb', line 173 def sunionstore(destination, *keys) keys.flatten!(1) send_command(RequestType::S_UNION_STORE, [destination].concat(keys)) end |