class Routemaster::EventIndex

Public Class Methods

new(url, cache: Config.cache_redis) click to toggle source
# File lib/routemaster/event_index.rb, line 4
def initialize(url, cache: Config.cache_redis)
  @url = url
  @cache = cache
end

Public Instance Methods

current() click to toggle source
# File lib/routemaster/event_index.rb, line 19
def current
  (@cache.hget(_key, 'current_index') || 0).to_i
end
increment() click to toggle source
# File lib/routemaster/event_index.rb, line 9
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

Private Instance Methods

_key() click to toggle source
# File lib/routemaster/event_index.rb, line 30
def _key
  @_key ||= CacheKey.url_key(@url)
end
_node() { |redis.node_for(namespaced_key), namespaced_key| ... } click to toggle source
# File lib/routemaster/event_index.rb, line 25
def _node
  namespaced_key = "#{@cache.namespace}:#{_key}"
  yield @cache.redis.node_for(namespaced_key), namespaced_key
end