Class: IpFilter::Cache::Redis

Inherits:
IpFilter::Cache show all
Defined in:
lib/ip_filter/cache/redis.rb

Instance Attribute Summary

Attributes inherited from IpFilter::Cache

#cached_at, #prefix, #store

Instance Method Summary collapse

Methods inherited from IpFilter::Cache

#initialize, #key_for, #serialize_output

Constructor Details

This class inherits a constructor from IpFilter::Cache

Instance Method Details

#[](ip) ⇒ Object

Read from the Cache.



13
14
15
16
17
# File 'lib/ip_filter/cache/redis.rb', line 13

def [](ip)
  value = store.get(key_for(ip))
  # this method is inherited from IpFilter::Cache
  serialize_output(value)
end

#[]=(ip, value) ⇒ Object

Write to the Cache.



20
21
22
# File 'lib/ip_filter/cache/redis.rb', line 20

def []=(ip, value)
  store.set(key_for(ip), value.to_json)
end

#resetObject



7
8
9
10
# File 'lib/ip_filter/cache/redis.rb', line 7

def reset
  keys = store.keys("#{@prefix}*")
  store.del keys unless keys.empty?
end