Class: Conflow::Redis::ArrayField Private
- 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
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
private
True if equal.
-
#each(&block) ⇒ Object
private
Iterates over list.
-
#overwrite(new_array) ⇒ Object
private
Replace contents of Redis list.
-
#push(*values) ⇒ String
(also: #<<)
private
Redis response.
-
#size ⇒ Integer
private
Number of elements in list.
-
#to_a ⇒ Array
(also: #to_ary)
private
Ruby Array representation of Redis list.
-
#to_s ⇒ Object
private
String representation of the list.
Methods inherited from Field
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.
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
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
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.
22 23 24 |
# File 'lib/conflow/redis/array_field.rb', line 22 def push(*values) command :rpush, [key, values] end |
#size ⇒ Integer
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.
11 12 13 |
# File 'lib/conflow/redis/array_field.rb', line 11 def size command :llen, [key] end |
#to_a ⇒ Array 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.
16 17 18 |
# File 'lib/conflow/redis/array_field.rb', line 16 def to_a command :lrange, [key, 0, -1] end |
#to_s ⇒ 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.
String representation of the list
55 56 57 |
# File 'lib/conflow/redis/array_field.rb', line 55 def to_s to_a.to_s end |