Sha256: 89e98225c1a23fa5cd221f170bdf29ba2e2ffb4cf7e91cb4cc5cfa2baebd4ee3

Contents?: true

Size: 600 Bytes

Versions: 4

Compression:

Stored size: 600 Bytes

Contents

module Restruct
  class Queue < Structure

    def push(object)
      connection.lazy 'RPUSH', id, serialize(object)
    end

    def pop
      deserialize connection.lazy('LPOP', id)
    end

    def size
      connection.call 'LLEN', id
    end
    alias_method :count, :size
    alias_method :length, :size

    def empty?
      size == 0
    end

    def to_a
      connection.call('LRANGE', id, 0, -1).map { |o| deserialize o }
    end
    alias_method :to_primitive, :to_a

    private

    def serialize(string)
      string
    end

    def deserialize(string)
      string
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
restruct-1.1.0 lib/restruct/queue.rb
restruct-1.0.0 lib/restruct/queue.rb
restruct-0.2.0 lib/restruct/queue.rb
restruct-0.1.0 lib/restruct/queue.rb