class ResqueAdmin::DataStore::QueueAccess

Public Class Methods

new(redis) click to toggle source
# File lib/resque_admin/data_store.rb, line 99
def initialize(redis)
  @redis = redis
end

Public Instance Methods

everything_in_queue(queue) click to toggle source
# File lib/resque_admin/data_store.rb, line 138
def everything_in_queue(queue)
  @redis.lrange(redis_key_for_queue(queue), 0, -1)
end
list_range(key, start = 0, count = 1) click to toggle source

Private: do not call

# File lib/resque_admin/data_store.rb, line 153
def list_range(key, start = 0, count = 1)
  if count == 1
    @redis.lindex(key, start)
  else
    Array(@redis.lrange(key, start, start+count-1))
  end
end
peek_in_queue(queue, start = 0, count = 1) click to toggle source

Examine items in the queue.

NOTE: if count is 1, you will get back an object, otherwise you will

get an Array.  I'm not making this up.
# File lib/resque_admin/data_store.rb, line 123
def peek_in_queue(queue, start = 0, count = 1)
  list_range(redis_key_for_queue(queue), start, count)
end
pop_from_queue(queue) click to toggle source

Pop whatever is on queue

# File lib/resque_admin/data_store.rb, line 110
def pop_from_queue(queue)
  @redis.lpop(redis_key_for_queue(queue))
end
push_to_queue(queue,encoded_item) click to toggle source
# File lib/resque_admin/data_store.rb, line 102
def push_to_queue(queue,encoded_item)
  @redis.pipelined do
    watch_queue(queue)
    @redis.rpush redis_key_for_queue(queue), encoded_item
  end
end
queue_names() click to toggle source
# File lib/resque_admin/data_store.rb, line 127
def queue_names
  Array(@redis.smembers(:queues))
end
queue_size(queue) click to toggle source

Get the number of items in the queue

# File lib/resque_admin/data_store.rb, line 115
def queue_size(queue)
  @redis.llen(redis_key_for_queue(queue)).to_i
end
remove_from_queue(queue,data) click to toggle source

Remove data from the queue, if it's there, returning the number of removed elements

# File lib/resque_admin/data_store.rb, line 143
def remove_from_queue(queue,data)
  @redis.lrem(redis_key_for_queue(queue), 0, data)
end
remove_queue(queue) click to toggle source
# File lib/resque_admin/data_store.rb, line 131
def remove_queue(queue)
  @redis.pipelined do
    @redis.srem(:queues, queue.to_s)
    @redis.del(redis_key_for_queue(queue))
  end
end
watch_queue(queue) click to toggle source

Private: do not call

# File lib/resque_admin/data_store.rb, line 148
def watch_queue(queue)
  @redis.sadd(:queues, queue.to_s)
end

Private Instance Methods

redis_key_for_queue(queue) click to toggle source
# File lib/resque_admin/data_store.rb, line 163
def redis_key_for_queue(queue)
  "queue:#{queue}"
end