lib/simple_throttle.rb in simple_throttle-1.0.2 vs lib/simple_throttle.rb in simple_throttle-1.0.3

- old
+ new

@@ -99,12 +99,12 @@ # @param limit [Integer] number of allowed requests within the throttle ttl # @param redis [Redis] Redis client to use def initialize(name, ttl:, limit:, redis: nil) @name = name.to_s @name = name.dup.freeze unless name.frozen? - @limit = limit - @ttl = ttl + @limit = limit.to_i + @ttl = ttl.to_f @redis = redis end # Returns true if the limit for the throttle has not been reached yet. This method # will also track the throttled resource as having been invoked on each call. @@ -150,10 +150,10 @@ # Evaluate and execute a Lua script on the redis server that returns the number calls currently being tracked. # If push is set to true then a new item will be added to the list. def current_size(push) push_arg = (push ? 1 : 0) time_ms = (Time.now.to_f * 1000).round - ttl_ms = ttl * 1000 + ttl_ms = (ttl * 1000).ceil self.class.send(:execute_lua_script, redis: redis_client, keys: [redis_key], args: [limit, ttl_ms, time_ms, push_arg]) end def redis_key "simple_throttle.#{name}"