Sha256: 114b05cdd11013f0853c9c09924cc8633479287d54ee76f12f7a6484715d4ddc

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module QPush
  module Web
    class << self
      def redis
        redis_pool.with do |conn|
          yield conn
        end
      end

      def redis_pool
        @redis_pool ||= QPush::Base::RedisPool.create(Web.config.redis_pool,
                                                      Web.config.redis_url)
      end
    end

    class RedisKeys
      KEYS = [:delay,
              :queue,
              :perform,
              :stats,
              :heart,
              :crons,
              :history,
              :morgue]

      attr_reader :delay, :queue, :perform, :stats, :heart,
                  :crons, :history, :morgue

      def initialize(options = {})
        @namespace = options[:namespace] || 'default'
        @priorities = options[:priorities] || 5
        build_keyspaces
      end

      def perform_list
        @perform_list ||= (1..@priorities).collect { |num| "#{perform}:#{num}" }
      end

      private

      def build_keyspaces
        KEYS.each do |key|
          instance_variable_set("@#{key}", "#{QPush::Base::KEY}:#{@namespace}:#{key}")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qpush-0.1.8 lib/qpush/web/redis.rb
qpush-0.1.7 lib/qpush/web/redis.rb