Sha256: 6868cdca4dfcda8ad012e5792d763ef1fe3c45f37e502149b1a6f88344d4d1f2

Contents?: true

Size: 833 Bytes

Versions: 2

Compression:

Stored size: 833 Bytes

Contents

module Sidekiq
  module Haron
    module Storage

      DEFAULT_EXPIRY = 30 * 24 * 60 * 60 # 30 days

      protected

      def store_for_id(id, data, redis_pool=nil)
        redis_connection(redis_pool) do |conn|
          conn.multi do
            conn.hmset  key(id), *(data.to_a.flatten(1))
            conn.expire key(id), DEFAULT_EXPIRY
          end[0]
        end
      end

      def read_for_id(id)
        Sidekiq.redis do |conn|
          conn.hgetall(key(id))
        end
      end

      private

      def redis_connection(redis_pool=nil)
        if redis_pool
          redis_pool.with do |conn|
            yield conn
          end
        else
          Sidekiq.redis do |conn|
            yield conn
          end
        end
      end

      def key(id)
        "sidekiq:haron:#{id}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sidekiq-haron-0.1.3 lib/sidekiq/haron/storage.rb
sidekiq-haron-0.1.2 lib/sidekiq/haron/storage.rb