class WithRateLimit::Cache::Redis

Public Class Methods

configure() { |configuration| ... } click to toggle source
# File lib/with_rate_limit/cache/redis.rb, line 17
def self.configure
  yield configuration
  return self
end
get(key) click to toggle source
# File lib/with_rate_limit/cache/redis.rb, line 13
def self.get(key)
  cache[key] || {}
end
set(key, values) click to toggle source
# File lib/with_rate_limit/cache/redis.rb, line 5
def self.set(key, values)
  cache_data = cache
  cache_data[key] ||= {}
  cache_data[key].merge!(values)
  
  redis_client.set('with-rate-limit', JSON(cache_data))
end

Private Class Methods

cache() click to toggle source
# File lib/with_rate_limit/cache/redis.rb, line 29
def self.cache
  redis_client.exists('with-rate-limit') ? JSON(redis_client.get('with-rate-limit')) : {}
end
configuration() click to toggle source
# File lib/with_rate_limit/cache/redis.rb, line 24
def self.configuration
  @redis_client = nil
  @configuration ||= {}
end
redis_client() click to toggle source
# File lib/with_rate_limit/cache/redis.rb, line 33
def self.redis_client
  @redis_client ||= ::Redis.new(configuration[:redis_options])
end