Class: ActiveEndpoint::Routes::Cache::Proxy::RedisStoreProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_endpoint/routes/cache/proxy/redis_store_proxy.rb

Instance Method Summary collapse

Constructor Details

#initializeRedisStoreProxy

Returns a new instance of RedisStoreProxy.



6
7
8
9
# File 'lib/active_endpoint/routes/cache/proxy/redis_store_proxy.rb', line 6

def initialize
  @prefix = ActiveEndpoint.cache_prefix
  @store = ::Redis::Store.new
end

Instance Method Details

#expires_in(unprefixed_key) ⇒ Object



27
28
29
30
# File 'lib/active_endpoint/routes/cache/proxy/redis_store_proxy.rb', line 27

def expires_in(unprefixed_key)
  time = @store.ttl(store_key(unprefixed_key)).to_i
  time == -1 || time == -2 ? 0 : time
end

#read(unprefixed_key) ⇒ Object



11
12
13
# File 'lib/active_endpoint/routes/cache/proxy/redis_store_proxy.rb', line 11

def read(unprefixed_key)
  @store.get("#{@prefix}:#{unprefixed_key}")
end

#write(unprefixed_key, value, expires_in = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/active_endpoint/routes/cache/proxy/redis_store_proxy.rb', line 15

def write(unprefixed_key, value, expires_in = nil)
  store_key = store_key(unprefixed_key)

  if expires_in.present?
    @store.setex(store_key, expires_in, value)
  else
    @store.set(store_key, value)
  end

  true
end