module Oxblood::Commands::Sets

Public Instance Methods

sadd(key, *members) click to toggle source

Add one or more members to a set @see redis.io/commands/sadd

@param [String] key under which store set @param [String, Array<String>] members to store

@return [Integer] the number of elements that were added to the set,

not including all the elements already present into the set.
# File lib/oxblood/commands/sets.rb, line 14
def sadd(key, *members)
  run(*members.unshift(:SADD, key))
end
scard(key) click to toggle source

Get the number of members in a set @see redis.io/commands/scard

@param [String] key

@return [Integer] the cardinality (number of elements) of the set, or 0 if

key does not exist
# File lib/oxblood/commands/sets.rb, line 25
def scard(key)
  run(:SCARD, key)
end
sdiff(*keys) click to toggle source

Subtract multiple sets @see redis.io/commands/sdiff

@param [String, Array<String>] keys

@return [Array] array with members of the resulting set

# File lib/oxblood/commands/sets.rb, line 35
def sdiff(*keys)
  run(*keys.unshift(:SDIFF))
end
sdiffstore(destination, *keys) click to toggle source

Subtract multiple sets and store the resulting set in a key @see redis.io/commands/sdiffstore

@param [String] destination key @param [String, Array<String>] keys of sets to diff

@return [Integer] the number of elements in the resulting set

# File lib/oxblood/commands/sets.rb, line 46
def sdiffstore(destination, *keys)
  run(*keys.unshift(:SDIFFSTORE, destination))
end
sinter(*keys) click to toggle source

Intersect multiple sets @see redis.io/commands/sinter

@param [String, Array<String>] keys to intersect

@return [Array] array with members of the resulting set

# File lib/oxblood/commands/sets.rb, line 56
def sinter(*keys)
  run(*keys.unshift(:SINTER))
end
sinterstore(destination, *keys) click to toggle source

Intersect multiple sets and store the resulting key in a key @see redis.io/commands/sinterstore

@param [String] destination key @param [String, Array<String>] keys of sets to intersect

@return [Integer] the number of elements in the resulting set

# File lib/oxblood/commands/sets.rb, line 67
def sinterstore(destination, *keys)
  run(*keys.unshift(:SINTERSTORE, destination))
end
sismember(key, member) click to toggle source

Determine if a given value is a member of a set @see redis.io/commands/sismember

@param [String] key @param [String] member

@return [Integer] 1 if the element is a member of the set or

0 if the element is not a member of the set, or if key does not exist
# File lib/oxblood/commands/sets.rb, line 79
def sismember(key, member)
  run(:SISMEMBER, key, member)
end
smembers(key) click to toggle source

Get all the members in a set @see redis.io/commands/smembers

@param [String] key

@return [Array] all elements of the set

# File lib/oxblood/commands/sets.rb, line 89
def smembers(key)
  run(:SMEMBERS, key)
end
smove(source, destination, member) click to toggle source

Move a member from one set to another @see redis.io/commands/smove

@param [String] source @param [String] destination @param [String] member

@return [Integer] 1 if the element is moved, or 0 if the element is not

a member of source and no operation was performed
# File lib/oxblood/commands/sets.rb, line 102
def smove(source, destination, member)
  run(:SMOVE, source, destination, member)
end
spop(key, count = nil) click to toggle source

Remove and return one or multiple random members from a set @see redis.io/commands/spop

@param [String] key @param [Integer] count

@return [String] without the additional count argument the command returns

the removed element, or nil when key does not exist

@return [Array] when the additional count argument is passed the command

returns an array of removed elements, or an empty array when key does
not exist.
# File lib/oxblood/commands/sets.rb, line 117
def spop(key, count = nil)
  args = [:SPOP, key]
  args << count if count
  run(*args)
end
srandmember(key, count = nil) click to toggle source

Get one or multiple random members from a set @see redis.io/commands/srandmember

@param [String] key @param [Integer] count

@return [String, nil] without the additional count argument the command

returns string with the randomly selected element, or nil when key
does not exist

@return [Array] when the additional count argument is passed the command

returns an array of elements, or an empty array when key does not exist
# File lib/oxblood/commands/sets.rb, line 134
def srandmember(key, count = nil)
  args = [:SRANDMEMBER, key]
  args << count if count
  run(*args)
end
srem(key, *members) click to toggle source

Remove one or more members from a set @see redis.io/commands/srem

@param [String] key @param [Array] members to remove

@return [Integer] the number of members that were removed from the set,

not including non existing members
# File lib/oxblood/commands/sets.rb, line 148
def srem(key, *members)
  run(*members.unshift(:SREM, key))
end
sscan(key, cursor, opts = {}) click to toggle source

Incrementally iterate Set elements @see redis.io/commands/sscan

@param [Integer] cursor @param [Hash] opts

@option opts [Integer] :count Amount of work that should be done at

every call in order to retrieve elements from the collection.

@option opts [String] :match

@return [Array] two elements array, where the first element is String

representing an unsigned 64 bit number (the cursor), and the second
element is an Array of elements.
# File lib/oxblood/commands/sets.rb, line 186
def sscan(key, cursor, opts = {})
  args = [:SSCAN, key, cursor]
  Scan.merge_opts!(args, opts)
  run(*args)
end
sunion(*keys) click to toggle source

Add multiple sets @see redis.io/commands/sunion

@param [String, Array<String>] keys

@return [Array] list with members of the resulting set

# File lib/oxblood/commands/sets.rb, line 158
def sunion(*keys)
  run(*keys.unshift(:SUNION))
end
sunionstore(destination, *keys) click to toggle source

Add multipe sets and store the resulting set in a key @see redis.io/commands/sunionstore

@param [String] destination @param [String, Array<String>] keys

@return [Integer] the number of elements in the resulting set

# File lib/oxblood/commands/sets.rb, line 169
def sunionstore(destination, *keys)
  run(*keys.unshift(:SUNIONSTORE, destination))
end