Sha256: c4a4b9ba79c4d9f709bbcde9e1044d7e9ef590e5c8dc8bf80ac817ec5a63649d

Contents?: true

Size: 733 Bytes

Versions: 3

Compression:

Stored size: 733 Bytes

Contents

module Counter
  module Cache
    class Redis
      def incr(key, val = 1)
        with_redis do |redis|
          redis.incrby key, val
        end
      end

      def decr(key, val = 1)
        with_redis do |redis|
          redis.decrby(key, val)
        end
      end

      def get(key)
        with_redis do |redis|
          redis.get(key)
        end
      end

      def del(key)
        with_redis do |redis|
          redis.del(key)
        end
      end

      private

      def with_redis
        redis_pool = Counter::Cache.configuration.redis_pool
        return yield redis_pool unless redis_pool.respond_to?(:with)

        redis_pool.with do |redis|
          yield redis
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
counter-cache-0.3.0 lib/counter/cache/redis.rb
counter-cache-0.2.0 lib/counter/cache/redis.rb
counter-cache-0.1.0 lib/counter/cache/redis.rb