Module: Trophonius::RedisManager
- Defined in:
- lib/connectors/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 14 |
# File 'lib/connectors/redis_manager.rb', line 4 def self.connect return unless Trophonius.config.redis_connection redis_url = ENV.fetch('REDIS_URL') = {} .merge!(url: redis_url) if redis_url && redis_url != '' .merge!(ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }) if Trophonius.config.redis_no_verify @redis ||= Redis.new() nil end |
.connected? ⇒ Boolean
Checks whether we are connected to redis
51 52 53 |
# File 'lib/connectors/redis_manager.rb', line 51 def self.connected? @redis.nil? == false && @redis.connected? end |
.disconnect ⇒ NilClass
Disconnects from redis as quickly and as silently as possible
59 60 61 |
# File 'lib/connectors/redis_manager.rb', line 59 def self.disconnect @redis.disconnect! end |
.get_key(key:) ⇒ String
Get the value corresponding with the key
31 32 33 34 |
# File 'lib/connectors/redis_manager.rb', line 31 def self.get_key(key:) connect unless connected? @redis.get(key) end |
.key_exists?(key:) ⇒ Boolean
Checks whether the given key exists
21 22 23 24 |
# File 'lib/connectors/redis_manager.rb', line 21 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
42 43 44 45 |
# File 'lib/connectors/redis_manager.rb', line 42 def self.set_key(key:, value:) connect unless connected? @redis.set(key, value) end |