lib/redis_ext/redis_queue.rb in gandalf-0.0.2 vs lib/redis_ext/redis_queue.rb in gandalf-0.0.3
- old
+ new
@@ -1,6 +1,5 @@
-require 'redis'
require 'json'
class RedisQueue
attr_accessor :key, :redis
@@ -18,22 +17,22 @@
begin
value = JSON.parse(@redis.lpop(@key))
new_hash = {}
value.each{|k, v| new_hash[k.to_sym] = v}
return new_hash
- rescue Exception => ex
- puts ex
+ # Returns nil on any kind of exception
+ rescue Exception
return nil
end
end
def length
@redis.llen(@key)
end
- def pop_first(length)
- list = []
- length.times do
+ def pop_first(count)
+ list = []
+ count.times do
element = self.pop
break unless element
list << element
end
list