Sha256: c00e39baf58cee7df3c690dddb6dbc486713812f490e7338dc6ac468f3a087c3
Contents?: true
Size: 1021 Bytes
Versions: 1
Compression:
Stored size: 1021 Bytes
Contents
require 'turnpike/base' module Turnpike class Queue < Base # Pop one or more items from the queue. # # n - Integer number of items to pop. # # Returns a String item, an Array of items, or nil if the queue is empty. def pop(n = 1) items = [] n.times do break unless item = redis.lpop(name) items << unpack(item) end n == 1 ? items.first : items end # Push items to the end of the queue. # # items - A splat Array of items. # # Returns the Integer size of the queue after the operation. def push(*items) redis.rpush(name, items.map { |i| pack(i) }) end alias << push # Returns the Integer size of the queue. def size redis.llen(name) end # Push items to the front of the queue. # # items - A splat Array of items. # # Returns the Integer size of the queue after the operation. def unshift(*items) redis.lpush(name, items.map { |i| pack(i) }) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
turnpike-0.7.0 | lib/turnpike/queue.rb |