Module: Trophonius::RedisManager
- Defined in:
- lib/trophonius_redis_manager.rb
Overview
the RedisManager module is used to create a (single) connection to a redis store.
Class Method Summary collapse
- .connect ⇒ Object
-
.connected? ⇒ Boolean
Checks whether we are connected to redis.
-
.disconnect ⇒ NilClass
Disconnects from redis as quickly and as silently as possible.
-
.get_key(key:) ⇒ String
Get the value corresponding with the key.
-
.key_exists?(key:) ⇒ Boolean
Checks whether the given key exists.
-
.set_key(key:, value:) ⇒ String
Set the value corresponding with a key.
Class Method Details
.connect ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/trophonius_redis_manager.rb', line 4 def self.connect if Trophonius.config.redis_connection if ENV['REDIS_URL'] && ENV['REDIS_URL'] != '' @redis ||= Redis.new(url: ENV['REDIS_URL']) else @redis ||= Redis.new end end return nil end |
.connected? ⇒ Boolean
Checks whether we are connected to redis
50 51 52 |
# File 'lib/trophonius_redis_manager.rb', line 50 def self.connected? @redis.nil? == false && @redis.connected? end |
.disconnect ⇒ NilClass
Disconnects from redis as quickly and as silently as possible
58 59 60 |
# File 'lib/trophonius_redis_manager.rb', line 58 def self.disconnect @redis.disconnect! end |
.get_key(key:) ⇒ String
Get the value corresponding with the key
30 31 32 33 |
# File 'lib/trophonius_redis_manager.rb', line 30 def self.get_key(key:) connect unless connected? @redis.get(key) end |
.key_exists?(key:) ⇒ Boolean
Checks whether the given key exists
20 21 22 23 |
# File 'lib/trophonius_redis_manager.rb', line 20 def self.key_exists?(key:) connect unless connected? !(@redis.get(key).nil? || @redis.get(key).empty?) end |
.set_key(key:, value:) ⇒ String
Set the value corresponding with a key
41 42 43 44 |
# File 'lib/trophonius_redis_manager.rb', line 41 def self.set_key(key:, value:) connect unless connected? @redis.set(key, value) end |