接口请求限流
This commit is contained in:
parent
f1ab52da5c
commit
9f40886c45
|
@ -1172,7 +1172,7 @@ class ApplicationController < ActionController::Base
|
||||||
else
|
else
|
||||||
record_count = 1
|
record_count = 1
|
||||||
end
|
end
|
||||||
tip_exception("非法请求") if record_count > 100
|
normal_status("请求太快,请稍后再试。") if record_count > 100
|
||||||
|
|
||||||
Rails.cache.write("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}", record_count, expires_in: 1.minute)
|
Rails.cache.write("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}", record_count, expires_in: 1.minute)
|
||||||
rescue
|
rescue
|
||||||
|
|
Loading…
Reference in New Issue