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

#clear, #elements, #remove

Methods inherited from Proxying

#failsafe, #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: <<



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

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

  multi do |pipeline|
    remove elements, pipeline: pipeline
    super(elements, pipeline: pipeline)
    pipeline.ltrim -limit, -1 if limit
  end
end

#prepend(elements) ⇒ Object



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

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

  multi do |pipeline|
    remove elements, pipeline: pipeline
    super(elements, pipeline: pipeline)
    pipeline.ltrim 0, (limit - 1) if limit
  end
end