Class: RedisThrottle::Api Private
- Inherits:
-
Object
- Object
- RedisThrottle::Api
- Defined in:
- lib/redis_throttle/api.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #acquire(strategies:, token:) ⇒ Boolean private
- #info(strategies:) ⇒ Hash{Concurrency => Integer, RateLimit => Integer} private
-
#initialize(redis) ⇒ Api
constructor
private
A new instance of Api.
- #release(strategies:, token:) ⇒ void private
- #reset(strategies:) ⇒ void private
- #strategies(match:) ⇒ Array<Concurrency, RateLimit> private
Constructor Details
#initialize(redis) ⇒ Api
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Api.
29 30 31 |
# File 'lib/redis_throttle/api.rb', line 29 def initialize(redis) @redis = redis end |
Instance Method Details
#acquire(strategies:, token:) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 |
# File 'lib/redis_throttle/api.rb', line 36 def acquire(strategies:, token:) execute(:ACQUIRE, to_params(strategies.sort_by(&:itself)) << :TOKEN << token << :TS << Time.now.to_i).zero? end |
#info(strategies:) ⇒ Hash{Concurrency => Integer, RateLimit => Integer}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 |
# File 'lib/redis_throttle/api.rb', line 70 def info(strategies:) strategies.zip(execute(:INFO, to_params(strategies) << :TS << Time.now.to_i)).to_h end |
#release(strategies:, token:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
43 44 45 |
# File 'lib/redis_throttle/api.rb', line 43 def release(strategies:, token:) execute(:RELEASE, to_params(strategies) << :TOKEN << token) end |
#reset(strategies:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
49 50 51 |
# File 'lib/redis_throttle/api.rb', line 49 def reset(strategies:) execute(:RESET, to_params(strategies)) end |
#strategies(match:) ⇒ Array<Concurrency, RateLimit>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/redis_throttle/api.rb', line 55 def strategies(match:) results = [] block = ->(key) { from_key(key)&.then { |strategy| results << strategy } } if redis_client? @redis.scan("MATCH", "#{NAMESPACE}:*:#{match}:*:*", &block) else @redis.scan_each(match: "#{NAMESPACE}:*:#{match}:*:*", &block) end results end |