Class: Kredis::Types::List

Inherits:
Proxying show all
Defined in:
lib/kredis/types/list.rb

Direct Known Subclasses

UniqueList

Instance Attribute Summary collapse

Attributes inherited from Proxying

#key, #proxy, #redis

Instance Method Summary collapse

Methods inherited from Proxying

#failsafe, #initialize, proxying

Constructor Details

This class inherits a constructor from Kredis::Types::Proxying

Instance Attribute Details

#typedObject

Returns the value of attribute typed.



4
5
6
# File 'lib/kredis/types/list.rb', line 4

def typed
  @typed
end

Instance Method Details

#append(*elements, pipeline: nil) ⇒ Object Also known as: <<



19
20
21
# File 'lib/kredis/types/list.rb', line 19

def append(*elements, pipeline: nil)
  (pipeline || proxy).rpush types_to_strings(elements, typed) if elements.flatten.any?
end

#clearObject



24
25
26
# File 'lib/kredis/types/list.rb', line 24

def clear
  del
end

#elementsObject Also known as: to_a



6
7
8
# File 'lib/kredis/types/list.rb', line 6

def elements
  strings_to_types(lrange(0, -1) || [], typed)
end

#prepend(*elements, pipeline: nil) ⇒ Object



15
16
17
# File 'lib/kredis/types/list.rb', line 15

def prepend(*elements, pipeline: nil)
  (pipeline || proxy).lpush types_to_strings(elements, typed) if elements.flatten.any?
end

#remove(*elements, pipeline: nil) ⇒ Object



11
12
13
# File 'lib/kredis/types/list.rb', line 11

def remove(*elements, pipeline: nil)
  types_to_strings(elements, typed).each { |element| (pipeline || proxy).lrem 0, element }
end