Module: Flex::LiveReindex::Redis

Extended by:
Redis
Included in:
Redis
Defined in:
lib/flex/live_reindex.rb

Overview

private module

Constant Summary collapse

KEYS =
{ :pid     => 'flex-reindexing-pid',
:changes => 'flex-reindexing-changes' }

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(command, key, *args) ⇒ Object



22
23
24
25
# File 'lib/flex/live_reindex.rb', line 22

def method_missing(command, key, *args)
  return unless Conf.redis
  Conf.redis.send(command, "#{KEYS[key]}-#{Conf.app_id}", *args)
end

Instance Method Details

#initObject

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/flex/live_reindex.rb', line 31

def init
  begin
    require 'redis'
  rescue LoadError
    raise MissingRedisError, 'The live-reindex feature rely on redis. Please, install redis and the "redis" gem.'
  end
  raise MissingAppIdError, 'You must set the Flex::Configuration.app_id, and be sure you deploy it before live-reindexing.' \
        if Conf.app_id.nil? || Conf.app_id.empty?
  raise LiveReindexInProgressError, %(It looks like a live-reindex is in progress (PID #{get(:pid)}). If you are sure that there is no live-reindex in progress, please run the "flex:reset_redis_keys" rake task and retry.) \
        if get(:pid)
  reset_keys # just in case
  set(:pid, $$)
end

#reset_keysObject



27
28
29
# File 'lib/flex/live_reindex.rb', line 27

def reset_keys
  KEYS.keys.each { |k| del k }
end