Class: Lawnchair::StorageEngine::Redis

Inherits:
Abstract
  • Object
show all
Defined in:
lib/storage_engine/redis.rb

Class Method Summary collapse

Methods inherited from Abstract

computed_key, db_connection?, fetch, get, log

Class Method Details

.data_storeObject



5
6
7
# File 'lib/storage_engine/redis.rb', line 5

def data_store
  Lawnchair.redis
end

.exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/storage_engine/redis.rb', line 17

def exists?(key)
  data_store.exists(computed_key(key))
end

.expire!(key) ⇒ Object



21
22
23
24
25
# File 'lib/storage_engine/redis.rb', line 21

def expire!(key)
  start_time = Time.now
  data_store.del(computed_key(key))
  log("EXPIRATION", key, Time.now-start_time)
end

.set(key, value, options = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/storage_engine/redis.rb', line 9

def set(key, value, options={})
  ttl   = options[:expires_in] || 3600
  value = Marshal.dump(value) unless options[:raw]
  
  data_store.set(computed_key(key), value)
  data_store.expireat(computed_key(key), (Time.now + ttl).to_i)
end