lib/rlimiter/redis_client.rb in rlimiter-1.0.2 vs lib/rlimiter/redis_client.rb in rlimiter-1.0.3
- old
+ new
@@ -28,11 +28,11 @@
#
# @param [Hash] params
# @return [Redis]
#
def initialize(params)
- @redis = Redis.new(params.deep_symbolize_keys)
+ @redis = Redis.new(params)
end
# Registers a hit corresponding to the key specified, requires the max hit count and the duration to be passed.
#
# @param [String] key : Should be unique for one operation, can be added for multiple operations if a single rate
@@ -74,12 +74,12 @@
# @param [Integer] count
# @param [Integer] duration
def next_in(key, count, duration)
@key = key
@duration = duration
- return 0 if current_count(key) <= count
- @duration - elapsed
+ return 0 if current_count(key) < count
+ [@duration - elapsed, 0].max
end
private
def reset
@@ -89,10 +89,10 @@
def incr_count
@redis.hincrby(@key, RATE_COUNT, 1)
end
def elapsed
- ((Time.now.getutc.to_f * 1000 - start_time) / 1000).to_i
+ ((Time.now.getutc.to_time.to_i * 1000 - start_time) / 1000).to_i
end
def start_time
@redis.hget(@key, START_TIME).to_i
end