Class: Conflow::Redis::ArrayField Private

Inherits:
Field
  • Object
show all
Includes:
Enumerable
Defined in:
lib/conflow/redis/array_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 Array 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

#==(other) ⇒ Boolean

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 true if equal.

Parameters:

Returns:

  • (Boolean)

    true if equal



45
46
47
48
49
50
51
# File 'lib/conflow/redis/array_field.rb', line 45

def ==(other)
  case other
  when Array      then to_a == other
  when ArrayField then key == other.key || to_a == other.to_a
  else super
  end
end

#each(&block) ⇒ Object

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.

Iterates over list

See Also:



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

def each(&block)
  to_a.each(&block)
end

#overwrite(new_array) ⇒ Object

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.

Replace contents of Redis list

Parameters:

  • new_array (Array)

    array of new values



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

def overwrite(new_array)
  redis.with do |conn|
    conn.pipelined do
      conn.del(key)
      conn.rpush(key, new_array)
    end
  end
end

#push(*values) ⇒ String Also known as: <<

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 Redis response.

Parameters:

  • values (String...)

    one or more values to be added to the list

Returns:

  • (String)

    Redis response



22
23
24
# File 'lib/conflow/redis/array_field.rb', line 22

def push(*values)
  command :rpush, [key, values]
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 list.

Returns:

  • (Integer)

    number of elements in list



11
12
13
# File 'lib/conflow/redis/array_field.rb', line 11

def size
  command :llen, [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 Ruby Array representation of Redis list.

Returns:

  • (Array)

    Ruby Array representation of Redis list



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

def to_a
  command :lrange, [key, 0, -1]
end

#to_sObject

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.

String representation of the list

See Also:



55
56
57
# File 'lib/conflow/redis/array_field.rb', line 55

def to_s
  to_a.to_s
end