Class: Routemaster::EventIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/routemaster/event_index.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, cache: Config.cache_redis) ⇒ EventIndex

Returns a new instance of EventIndex.



4
5
6
7
# File 'lib/routemaster/event_index.rb', line 4

def initialize(url, cache: Config.cache_redis)
  @url = url
  @cache = cache
end

Instance Method Details

#currentObject



19
20
21
# File 'lib/routemaster/event_index.rb', line 19

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

#incrementObject



9
10
11
12
13
14
15
16
17
# 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