Sha256: d64c9662240f7aca4a461df4b8946aacdbee81fd6d0ae6ee464f328d0403611e

Contents?: true

Size: 525 Bytes

Versions: 7

Compression:

Stored size: 525 Bytes

Contents

# 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

  attr_accessor :typed, :limit

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kredis-0.4.0 lib/kredis/types/unique_list.rb
kredis-0.3.1 lib/kredis/types/unique_list.rb
kredis-0.3.0 lib/kredis/types/unique_list.rb
kredis-0.2.3 lib/kredis/types/unique_list.rb
kredis-0.2.2 lib/kredis/types/unique_list.rb
kredis-0.2.1 lib/kredis/types/unique_list.rb
kredis-0.2.0 lib/kredis/types/unique_list.rb