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

Instance Method Summary collapse

Methods inherited from List

#clear, #elements, #last, #remove

Methods included from DefaultValues

#initialize

Methods inherited from Proxying

#failsafe, #initialize, proxying, #unproxied_redis

Instance Attribute Details

#limitObject

Returns the value of attribute limit.



7
8
9
# File 'lib/kredis/types/unique_list.rb', line 7

def limit
  @limit
end

#typedObject

Returns the value of attribute typed.



7
8
9
# File 'lib/kredis/types/unique_list.rb', line 7

def typed
  @typed
end

Instance Method Details

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



20
21
22
23
24
25
26
27
28
29
# File 'lib/kredis/types/unique_list.rb', line 20

def append(elements)
  elements = Array(elements).uniq
  return if elements.empty?

  multi do
    remove elements
    super
    ltrim(-limit, -1) if limit
  end
end

#prepend(elements) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/kredis/types/unique_list.rb', line 9

def prepend(elements)
  elements = Array(elements).uniq
  return if elements.empty?

  multi do
    remove elements
    super
    ltrim 0, (limit - 1) if limit
  end
end