Class: Kredis::Types::UniqueList

Inherits:
List show all
Defined in:
lib/kredis/types/unique_list.rb

Overview

You’d normally call this a set, but Redis already has another data type for that

Instance Attribute Summary collapse

Attributes inherited from Proxying

#key, #proxy, #redis

Instance Method Summary collapse

Methods inherited from List

#elements, #remove

Methods inherited from Proxying

#initialize, proxying

Constructor Details

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

Instance Attribute Details

#limitObject

Returns the value of attribute limit.



5
6
7
# File 'lib/kredis/types/unique_list.rb', line 5

def limit
  @limit
end

#typedObject

Returns the value of attribute typed.



5
6
7
# File 'lib/kredis/types/unique_list.rb', line 5

def typed
  @typed
end

Instance Method Details

#append(elements) ⇒ Object Also known as: <<



15
16
17
18
19
20
21
# File 'lib/kredis/types/unique_list.rb', line 15

def append(elements)
  multi do
    remove elements
    super
    ltrim (limit - 1), -1 if limit
  end if Array(elements).flatten.any?
end

#prepend(elements) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/kredis/types/unique_list.rb', line 7

def prepend(elements)
  multi do
    remove elements
    super
    ltrim 0, (limit - 1) if limit
  end if Array(elements).flatten.any?
end