require 'json' class RedisQueue attr_accessor :key, :redis def initialize(options = {}) @key = options[:key] @redis = (options[:redis] || Redis.new(options)) end def push(value) @redis.rpush(@key, value.to_json) end def pop begin value = JSON.parse(@redis.lpop(@key)) new_hash = {} value.each{|k, v| new_hash[k.to_sym] = v} return new_hash # Returns nil on any kind of exception rescue Exception return nil end end def length @redis.llen(@key) end def pop_first(count) list = [] count.times do element = self.pop break unless element list << element end list end end