接口请求限流

This commit is contained in:
xxqfamous 2023-06-08 13:58:07 +08:00
parent f1ab52da5c
commit 9f40886c45
1 changed files with 1 additions and 1 deletions

View File

@ -1172,7 +1172,7 @@ class ApplicationController < ActionController::Base
else
record_count = 1
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)
rescue