Class: CollectionSpace::RefCache::Backend::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/collectionspace/refcache/backend/redis.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Redis

Returns a new instance of Redis.



9
10
11
12
# File 'lib/collectionspace/refcache/backend/redis.rb', line 9

def initialize(url)
  # https://devcenter.heroku.com/articles/heroku-redis#connecting-in-rails
  @c = ::Redis.new(url: url, ssl_params: {verify_mode: OpenSSL::SSL::VERIFY_NONE})
end

Instance Method Details

#cleanObject



14
15
16
17
# File 'lib/collectionspace/refcache/backend/redis.rb', line 14

def clean
  # blank method; Redis handles removal of expired keys automagically, as per
  #  https://redis.io/commands/expire
end

#connected?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/collectionspace/refcache/backend/redis.rb', line 19

def connected?
  @c.ping
rescue
  false
end

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/collectionspace/refcache/backend/redis.rb', line 25

def exists?(key)
  @c.exists?(key)
end

#flushObject



29
30
31
# File 'lib/collectionspace/refcache/backend/redis.rb', line 29

def flush
  @c.flushdb
end

#get(key) ⇒ Object



33
34
35
# File 'lib/collectionspace/refcache/backend/redis.rb', line 33

def get(key)
  @c.get(key)
end

#put(key, value, lifetime: nil) ⇒ Object



37
38
39
# File 'lib/collectionspace/refcache/backend/redis.rb', line 37

def put(key, value, lifetime: nil)
  @c.set(key, value, ex: lifetime)
end

#remove(key) ⇒ Object



41
42
43
# File 'lib/collectionspace/refcache/backend/redis.rb', line 41

def remove(key)
  @c.del(key)
end

#sizeObject



45
46
47
# File 'lib/collectionspace/refcache/backend/redis.rb', line 45

def size
  @c.dbsize
end