Class: Restruct::Queue

Inherits:
Structure show all
Defined in:
lib/restruct/queue.rb

Direct Known Subclasses

MarshalQueue

Instance Attribute Summary

Attributes inherited from Structure

#connection, #id

Instance Method Summary collapse

Methods inherited from Structure

#==, #destroy, #dump, #exists?, #initialize, #restore

Constructor Details

This class inherits a constructor from Restruct::Structure

Instance Method Details

#empty?Boolean



18
19
20
# File 'lib/restruct/queue.rb', line 18

def empty?
  size == 0
end

#popObject



8
9
10
# File 'lib/restruct/queue.rb', line 8

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

#push(object) ⇒ Object



4
5
6
# File 'lib/restruct/queue.rb', line 4

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

#sizeObject Also known as: count, length



12
13
14
# File 'lib/restruct/queue.rb', line 12

def size
  connection.call 'LLEN', id
end

#to_aObject Also known as: to_primitive



22
23
24
# File 'lib/restruct/queue.rb', line 22

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