Class: HTTParty::Cache::Store::Redis
- Defined in:
- lib/httparty/cache/store/redis.rb
Constant Summary collapse
- NIL =
A Marshaled ‘nil` value
"\x04\b0"
Instance Attribute Summary collapse
- #options ⇒ Hash readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#_dump(level) ⇒ Object
I couldn’t get this to work! It’s never called even if I dump the store directly.
- #clear ⇒ Object
-
#delete(key) ⇒ nil
Removes a key from Redis.
-
#get(key) ⇒ Response?
Retrieves a key.
-
#getset(key) ⇒ Response?
Returns a key or set its value to a block result.
-
#initialize(redis_url: nil) ⇒ Redis
constructor
A new instance of Redis.
-
#key?(key) ⇒ Boolean
Discovers if a key exists.
- #marshal_dump ⇒ Object
- #marshal_load(redis_url) ⇒ Object
-
#set(key, response) ⇒ Response
Stores a Marshaled value indexed by a key.
Constructor Details
#initialize(redis_url: nil) ⇒ Redis
Returns a new instance of Redis.
23 24 25 |
# File 'lib/httparty/cache/store/redis.rb', line 23 def initialize(redis_url: nil) marshal_load(redis_url) end |
Instance Attribute Details
#options ⇒ Hash (readonly)
20 21 22 |
# File 'lib/httparty/cache/store/redis.rb', line 20 def @options end |
Class Method Details
._load(string) ⇒ Object
45 46 47 |
# File 'lib/httparty/cache/store/redis.rb', line 45 def self._load(string) new(redis_url: string) end |
Instance Method Details
#_dump(level) ⇒ Object
I couldn’t get this to work! It’s never called even if I dump the store directly
41 42 43 |
# File 'lib/httparty/cache/store/redis.rb', line 41 def _dump(level) [:redis_url] end |
#clear ⇒ Object
94 95 96 97 |
# File 'lib/httparty/cache/store/redis.rb', line 94 def clear redis('FLUSHALL', 'SYNC') nil end |
#delete(key) ⇒ nil
Removes a key from Redis
81 82 83 84 |
# File 'lib/httparty/cache/store/redis.rb', line 81 def delete(key) redis('DEL', key) nil end |
#get(key) ⇒ Response?
Retrieves a key
53 54 55 |
# File 'lib/httparty/cache/store/redis.rb', line 53 def get(key) Marshal.load(redis('GET', key) || NIL) end |
#getset(key) ⇒ Response?
Returns a key or set its value to a block result
71 72 73 74 75 |
# File 'lib/httparty/cache/store/redis.rb', line 71 def getset(key) return get(key) if key?(key) set(key, yield) end |
#key?(key) ⇒ Boolean
Discovers if a key exists
90 91 92 |
# File 'lib/httparty/cache/store/redis.rb', line 90 def key?(key) redis('EXISTS', key).positive? end |
#marshal_dump ⇒ Object
27 28 29 |
# File 'lib/httparty/cache/store/redis.rb', line 27 def marshal_dump [:redis_url] end |
#marshal_load(redis_url) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/httparty/cache/store/redis.rb', line 31 def marshal_load(redis_url) @options = {} @options[:redis_url] = redis_url || ENV['REDIS_URL'] @config = RedisClient.config(url: @options[:redis_url]) @redis = @config.new_pool(size: 2) @redis.call('PING') end |
#set(key, response) ⇒ Response
Stores a Marshaled value indexed by a key.
62 63 64 65 |
# File 'lib/httparty/cache/store/redis.rb', line 62 def set(key, response) redis('SET', key, Marshal.dump(response)) response end |