Module: Flex::LiveReindex::Redis

Extended by:
Redis
Included in:
Redis
Defined in:
lib/flex/live_reindex_admin.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



25
26
27
28
# File 'lib/flex/live_reindex_admin.rb', line 25

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:



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/flex/live_reindex_admin.rb', line 34

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



30
31
32
# File 'lib/flex/live_reindex_admin.rb', line 30

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