Module: Oxblood::Commands::Sets

Included in:
Oxblood::Commands
Defined in:
lib/oxblood/commands/sets.rb

Instance Method Summary collapse

Instance Method Details

#sadd(key, *members) ⇒ Integer

Add one or more members to a set

Parameters:

  • key (String)

    under which store set

  • members (String, Array<String>)

    to store

Returns:

  • (Integer)

    the number of elements that were added to the set, not including all the elements already present into the set.

See Also:


14
15
16
# File 'lib/oxblood/commands/sets.rb', line 14

def sadd(key, *members)
  run(*members.unshift(:SADD, key))
end

#scard(key) ⇒ Integer

Get the number of members in a set

Parameters:

  • key (String)

Returns:

  • (Integer)

    the cardinality (number of elements) of the set, or 0 if key does not exist

See Also:


25
26
27
# File 'lib/oxblood/commands/sets.rb', line 25

def scard(key)
  run(:SCARD, key)
end

#sdiff(*keys) ⇒ Array

Subtract multiple sets

Parameters:

  • keys (String, Array<String>)

Returns:

  • (Array)

    array with members of the resulting set

See Also:


35
36
37
# File 'lib/oxblood/commands/sets.rb', line 35

def sdiff(*keys)
  run(*keys.unshift(:SDIFF))
end

#sdiffstore(destination, *keys) ⇒ Integer

Subtract multiple sets and store the resulting set in a key

Parameters:

  • destination (String)

    key

  • keys (String, Array<String>)

    of sets to diff

Returns:

  • (Integer)

    the number of elements in the resulting set

See Also:


46
47
48
# File 'lib/oxblood/commands/sets.rb', line 46

def sdiffstore(destination, *keys)
  run(*keys.unshift(:SDIFFSTORE, destination))
end

#sinter(*keys) ⇒ Array

Intersect multiple sets

Parameters:

  • keys (String, Array<String>)

    to intersect

Returns:

  • (Array)

    array with members of the resulting set

See Also:


56
57
58
# File 'lib/oxblood/commands/sets.rb', line 56

def sinter(*keys)
  run(*keys.unshift(:SINTER))
end

#sinterstore(destination, *keys) ⇒ Integer

Intersect multiple sets and store the resulting key in a key

Parameters:

  • destination (String)

    key

  • keys (String, Array<String>)

    of sets to intersect

Returns:

  • (Integer)

    the number of elements in the resulting set

See Also:


67
68
69
# File 'lib/oxblood/commands/sets.rb', line 67

def sinterstore(destination, *keys)
  run(*keys.unshift(:SINTERSTORE, destination))
end

#sismember(key, member) ⇒ Integer

Determine if a given value is a member of a set

Parameters:

  • key (String)
  • member (String)

Returns:

  • (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

See Also:


79
80
81
# File 'lib/oxblood/commands/sets.rb', line 79

def sismember(key, member)
  run(:SISMEMBER, key, member)
end

#smembers(key) ⇒ Array

Get all the members in a set

Parameters:

  • key (String)

Returns:

  • (Array)

    all elements of the set

See Also:


89
90
91
# File 'lib/oxblood/commands/sets.rb', line 89

def smembers(key)
  run(:SMEMBERS, key)
end

#smove(source, destination, member) ⇒ Integer

Move a member from one set to another

Parameters:

  • source (String)
  • destination (String)
  • member (String)

Returns:

  • (Integer)

    1 if the element is moved, or 0 if the element is not a member of source and no operation was performed

See Also:


102
103
104
# File 'lib/oxblood/commands/sets.rb', line 102

def smove(source, destination, member)
  run(:SMOVE, source, destination, member)
end

#spop(key, count = nil) ⇒ String, Array

Remove and return one or multiple random members from a set

Parameters:

  • key (String)
  • count (Integer) (defaults to: nil)

Returns:

  • (String)

    without the additional count argument the command returns the removed element, or nil when key does not exist

  • (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.

See Also:


117
118
119
120
121
# 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) ⇒ String, ...

Get one or multiple random members from a set

Parameters:

  • key (String)
  • count (Integer) (defaults to: nil)

Returns:

  • (String, nil)

    without the additional count argument the command returns string with the randomly selected element, or nil when key does not exist

  • (Array)

    when the additional count argument is passed the command returns an array of elements, or an empty array when key does not exist

See Also:


134
135
136
137
138
# 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) ⇒ Integer

Remove one or more members from a set

Parameters:

  • key (String)
  • members (Array)

    to remove

Returns:

  • (Integer)

    the number of members that were removed from the set, not including non existing members

See Also:


148
149
150
# File 'lib/oxblood/commands/sets.rb', line 148

def srem(key, *members)
  run(*members.unshift(:SREM, key))
end

#sscan(key, cursor, opts = {}) ⇒ Array

Incrementally iterate Set elements

Parameters:

  • cursor (Integer)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :count (Integer)

    Amount of work that should be done at every call in order to retrieve elements from the collection.

  • :match (String)

Returns:

  • (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.

See Also:


186
187
188
189
190
# 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) ⇒ Array

Add multiple sets

Parameters:

  • keys (String, Array<String>)

Returns:

  • (Array)

    list with members of the resulting set

See Also:


158
159
160
# File 'lib/oxblood/commands/sets.rb', line 158

def sunion(*keys)
  run(*keys.unshift(:SUNION))
end

#sunionstore(destination, *keys) ⇒ Integer

Add multipe sets and store the resulting set in a key

Parameters:

  • destination (String)
  • keys (String, Array<String>)

Returns:

  • (Integer)

    the number of elements in the resulting set

See Also:


169
170
171
# File 'lib/oxblood/commands/sets.rb', line 169

def sunionstore(destination, *keys)
  run(*keys.unshift(:SUNIONSTORE, destination))
end