Module: Counter::Cache::Credis::ClassMethods

Defined in:
lib/counter/cache/credis/counter.rb

Instance Method Summary collapse

Instance Method Details

#counter_cache_redis(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/counter/cache/credis/counter.rb', line 19

def counter_cache_redis(options = {})
  mattr_accessor :column_delay
  delay = options[:delay] || 20
  column = options[:column] || 'views_count'
  self.column_delay = {} if self.column_delay.nil?
  self.column_delay[column] = delay
  defind_column_getter(column)
  include Counter::Cache::Credis::InstanceMethods
end

#defind_column_getter(column) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/counter/cache/credis/counter.rb', line 11

def defind_column_getter(column)
  self.class_eval do
    define_method("get_#{column}_cache") do
      self.send(column) + RedisCli.new.get("#{self.class.table_name}/#{column}#{self.id}").to_i
    end
  end
end