Class: Conflow::Redis::SetField Private

Inherits:
Field
  • Object
show all
Includes:
Enumerable
Defined in:
lib/conflow/redis/set_field.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents Redis list. It’s methods mirror most used Set methods.

Instance Attribute Summary

Attributes inherited from Field

#key

Instance Method Summary collapse

Methods inherited from Field

#initialize

Constructor Details

This class inherits a constructor from Conflow::Redis::Field

Instance Method Details

#add(*values) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds one or more elements to the set.

Examples:

Adding multiple fields

field.add(:last, :first, :other, :first)

Parameters:

  • values (String)

    list of values to be added

Returns:

  • (String)

    Redis response



16
17
18
# File 'lib/conflow/redis/set_field.rb', line 16

def add(*values)
  command :sadd, [key, values]
end

#overwrite(enumerable) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes old values from the set and overrides them with new.

Parameters:

  • enumerable (Enumerable)

    new values of the set

Returns:

  • (String)

    Redis response



28
29
30
31
32
33
34
35
# File 'lib/conflow/redis/set_field.rb', line 28

def overwrite(enumerable)
  redis.with do |conn|
    conn.pipelined do
      conn.del(key)
      conn.sadd(key, enumerable)
    end
  end
end

#sizeInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Number of elements in the set.

Returns:

  • (Integer)

    Number of elements in the set



21
22
23
# File 'lib/conflow/redis/set_field.rb', line 21

def size
  command :scard, [key]
end

#to_aArray Also known as: to_ary

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns array with set values

Returns:

  • (Array)

    values from the set



39
40
41
# File 'lib/conflow/redis/set_field.rb', line 39

def to_a
  command :smembers, [key]
end