Sha256: a74786123e4182be61e9aca5b39e9fdf51222e03e9f4afd418c3d2796582a07a

Contents?: true

Size: 632 Bytes

Versions: 3

Compression:

Stored size: 632 Bytes

Contents

# frozen_string_literal: true

# You'd normally call this a set, but Redis already has another data type for that
class Kredis::Types::UniqueList < Kredis::Types::List
  proxying :multi, :ltrim, :exists?

  attr_accessor :typed, :limit

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

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kredis-1.7.0 lib/kredis/types/unique_list.rb
kredis-1.6.1 lib/kredis/types/unique_list.rb
kredis-1.6.0 lib/kredis/types/unique_list.rb