Class: BrainzLab::Utilities::RateLimiter::RedisStore
- Inherits:
-
Object
- Object
- BrainzLab::Utilities::RateLimiter::RedisStore
- Defined in:
- lib/brainzlab/utilities/rate_limiter.rb
Overview
Redis store adapter
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(redis) ⇒ RedisStore
constructor
A new instance of RedisStore.
- #set(key, value, ttl: nil) ⇒ Object
Constructor Details
#initialize(redis) ⇒ RedisStore
Returns a new instance of RedisStore.
202 203 204 |
# File 'lib/brainzlab/utilities/rate_limiter.rb', line 202 def initialize(redis) @redis = redis end |
Instance Method Details
#delete(key) ⇒ Object
224 225 226 |
# File 'lib/brainzlab/utilities/rate_limiter.rb', line 224 def delete(key) @redis.del("brainzlab:ratelimit:#{key}") end |
#get(key) ⇒ Object
206 207 208 209 210 211 212 213 |
# File 'lib/brainzlab/utilities/rate_limiter.rb', line 206 def get(key) data = @redis.get("brainzlab:ratelimit:#{key}") return nil unless data JSON.parse(data, symbolize_names: true) rescue StandardError nil end |
#set(key, value, ttl: nil) ⇒ Object
215 216 217 218 219 220 221 222 |
# File 'lib/brainzlab/utilities/rate_limiter.rb', line 215 def set(key, value, ttl: nil) full_key = "brainzlab:ratelimit:#{key}" if ttl @redis.setex(full_key, ttl, value.to_json) else @redis.set(full_key, value.to_json) end end |