Sha256: 72a5c164ad88bca49cbd30c262a55e4b7f70e6eaad9fd1391361d14f1822515c

Contents?: true

Size: 676 Bytes

Versions: 19

Compression:

Stored size: 676 Bytes

Contents

require 'routemaster/cache_key'
module Routemaster
  class EventIndex
    def initialize(url, cache: Config.cache_redis)
      @url = url
      @cache = cache
    end

    def increment
      _node do |cache, key|
        cache.multi do |m|
          m.hincrby(key, 'current_index', 1)
          m.expire(key, Config.cache_expiry)
        end
      end
      self
    end

    def current
      (@cache.hget(_key, 'current_index') || 0).to_i
    end

    private

    def _node
      namespaced_key = "#{@cache.namespace}:#{_key}"
      yield @cache.redis.node_for(namespaced_key), namespaced_key
    end

    def _key
      @_key ||= CacheKey.url_key(@url)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
routemaster-drain-3.7.1 lib/routemaster/event_index.rb
routemaster-drain-3.7.0 lib/routemaster/event_index.rb
routemaster-drain-3.6.8 lib/routemaster/event_index.rb
routemaster-drain-3.6.7 lib/routemaster/event_index.rb
routemaster-drain-3.6.6 lib/routemaster/event_index.rb
routemaster-drain-3.6.5 lib/routemaster/event_index.rb
routemaster-drain-3.6.4 lib/routemaster/event_index.rb
routemaster-drain-3.6.3 lib/routemaster/event_index.rb
routemaster-drain-3.6.2 lib/routemaster/event_index.rb
routemaster-drain-3.6.1 lib/routemaster/event_index.rb
routemaster-drain-3.6.0 lib/routemaster/event_index.rb
routemaster-drain-3.5.1 lib/routemaster/event_index.rb
routemaster-drain-3.5.0 lib/routemaster/event_index.rb
routemaster-drain-3.4.0 lib/routemaster/event_index.rb
routemaster-drain-3.3.0 lib/routemaster/event_index.rb
routemaster-drain-3.2.0 lib/routemaster/event_index.rb
routemaster-drain-3.1.0 lib/routemaster/event_index.rb
routemaster-drain-3.0.3 lib/routemaster/event_index.rb
routemaster-drain-3.0.2 lib/routemaster/event_index.rb