Browse Source

接口请求限流

pull/343/head
xxqfamous 3 years ago
parent
commit
9f40886c45
1 changed files with 1 additions and 1 deletions
  1. +1
    -1
      app/controllers/application_controller.rb

+ 1
- 1
app/controllers/application_controller.rb View File

@@ -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…
Cancel
Save