Class: WebFetch::Storage::Redis
- Inherits:
-
Object
- Object
- WebFetch::Storage::Redis
- Defined in:
- lib/web_fetch/storage/redis.rb
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #fetch(key) ⇒ Object
-
#initialize(client = nil) ⇒ Redis
constructor
A new instance of Redis.
- #store(key, obj) ⇒ Object
Constructor Details
#initialize(client = nil) ⇒ Redis
Returns a new instance of Redis.
6 7 8 9 10 11 12 13 |
# File 'lib/web_fetch/storage/redis.rb', line 6 def initialize(client = nil) require 'redis' if client.nil? @client = client || ::Redis @config = { host: ENV.fetch('WEB_FETCH_REDIS_HOST', 'localhost'), port: ENV.fetch('WEB_FETCH_REDIS_PORT', '6379') } end |
Instance Method Details
#delete(key) ⇒ Object
26 27 28 |
# File 'lib/web_fetch/storage/redis.rb', line 26 def delete(key) storage.del(key) end |
#fetch(key) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/web_fetch/storage/redis.rb', line 19 def fetch(key) result = storage.get(key) return JSON.parse(result, symbolize_names: true) unless result.nil? nil end |
#store(key, obj) ⇒ Object
15 16 17 |
# File 'lib/web_fetch/storage/redis.rb', line 15 def store(key, obj) storage.set(key, obj.to_json, ex: ttl) end |