Sha256: f0369a0e5e48c0e8bea87d12e9f56a3fc17231f8dc158a1f761b1d82d32380c5
Contents?: true
Size: 689 Bytes
Versions: 2
Compression:
Stored size: 689 Bytes
Contents
require 'redis' 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 rescue Exception => ex puts ex return nil end end def length @redis.llen(@key) end def pop_first(length) list = [] length.times do element = self.pop break unless element list << element end list end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gandalf-0.0.2 | lib/redis_ext/redis_queue.rb |
gandalf-0.0.1 | lib/redis_ext/redis_queue.rb |