diff options
Diffstat (limited to 'lib/gitlab/application_rate_limiter/increment_per_action.rb')
-rw-r--r-- | lib/gitlab/application_rate_limiter/increment_per_action.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/gitlab/application_rate_limiter/increment_per_action.rb b/lib/gitlab/application_rate_limiter/increment_per_action.rb new file mode 100644 index 00000000000..c99d03f1344 --- /dev/null +++ b/lib/gitlab/application_rate_limiter/increment_per_action.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Gitlab + module ApplicationRateLimiter + class IncrementPerAction < BaseStrategy + def increment(cache_key, expiry) + with_redis do |redis| + redis.pipelined do + redis.incr(cache_key) + redis.expire(cache_key, expiry) + end.first + end + end + + def read(cache_key) + with_redis do |redis| + redis.get(cache_key).to_i + end + end + end + end +end |