class Ost::Queue

Attributes

backup[R]
key[R]

Public Class Methods

new(name) click to toggle source
# File lib/ost.rb, line 11
def initialize(name)
  @key = Nido.new(:ost)[name]
  @backup = @key[Socket.gethostname][Process.pid]
  @stopping = false
end

Public Instance Methods

<<(value)
Alias for: push
each(&block) click to toggle source
# File lib/ost.rb, line 21
def each(&block)
  loop do
    item = redis.call("BRPOPLPUSH", @key, @backup, TIMEOUT)

    if item
      block.call(item)
      redis.call("LPOP", @backup)
    end

    break if @stopping
  end
end
Also aliased as: pop
items() click to toggle source
# File lib/ost.rb, line 38
def items
  redis.call("LRANGE", @key, 0, -1)
end
pop(&block)
Alias for: each
push(value) click to toggle source
# File lib/ost.rb, line 17
def push(value)
  redis.call("LPUSH", @key, value)
end
Also aliased as: <<
redis() click to toggle source
# File lib/ost.rb, line 49
def redis
  defined?(@redis) ? @redis : Ost.redis
end
redis=(redis) click to toggle source
# File lib/ost.rb, line 53
def redis=(redis)
  @redis = redis
end
size() click to toggle source
# File lib/ost.rb, line 45
def size
  redis.call("LLEN", @key)
end
stop() click to toggle source
# File lib/ost.rb, line 34
def stop
  @stopping = true
end