Class: WhoIsOnline::RedisStore
- Inherits:
-
Object
- Object
- WhoIsOnline::RedisStore
- Defined in:
- lib/whoisonline/redis_store.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #delete_presence(key) ⇒ Object
- #exists?(key) ⇒ Boolean
-
#initialize(configuration) ⇒ RedisStore
constructor
A new instance of RedisStore.
- #scan_keys(match:) ⇒ Object
- #write_presence(key, value, ttl_seconds) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ RedisStore
Returns a new instance of RedisStore.
5 6 7 |
# File 'lib/whoisonline/redis_store.rb', line 5 def initialize(configuration) @configuration = configuration end |
Instance Method Details
#connection ⇒ Object
9 10 11 |
# File 'lib/whoisonline/redis_store.rb', line 9 def connection @connection ||= @configuration.redis_connection end |
#delete_presence(key) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/whoisonline/redis_store.rb', line 36 def delete_presence(key) connection.del(key) rescue StandardError => e log(:warn, "whoisonline delete failed: #{e.class} #{e.}") nil end |
#exists?(key) ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/whoisonline/redis_store.rb', line 20 def exists?(key) connection.exists?(key) rescue StandardError => e log(:warn, "whoisonline exists? failed: #{e.class} #{e.}") false end |
#scan_keys(match:) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/whoisonline/redis_store.rb', line 27 def scan_keys(match:) return enum_for(:scan_keys, match: match) unless block_given? connection.scan_each(match: match) { |key| yield key } rescue StandardError => e log(:warn, "whoisonline scan failed: #{e.class} #{e.}") [] end |
#write_presence(key, value, ttl_seconds) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/whoisonline/redis_store.rb', line 13 def write_presence(key, value, ttl_seconds) connection.set(key, value, ex: ttl_seconds) rescue StandardError => e log(:warn, "whoisonline write failed: #{e.class} #{e.}") nil end |