Class: Web::RedisCache

Inherits:
Object
  • Object
show all
Defined in:
lib/web/cache/redis_cache.rb

Overview

A basic cache interface, implemented with Redis

Instance Method Summary collapse

Constructor Details

#initialize(client = nil) ⇒ RedisCache

Returns a new instance of RedisCache.



9
10
11
# File 'lib/web/cache/redis_cache.rb', line 9

def initialize(client = nil)
  @redis = client || Redis.new
end

Instance Method Details

#get(key) ⇒ Object



13
14
15
# File 'lib/web/cache/redis_cache.rb', line 13

def get(key)
  @redis.get key
end

#set(key, value, expires = nil) ⇒ Object



17
18
19
20
# File 'lib/web/cache/redis_cache.rb', line 17

def set(key, value, expires = nil)
  @redis.set key, value
  @redis.expire key, expires if expires
end