Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问如何限制链接允许连接的最多ip数量? #4

Open
jakkpop opened this issue May 9, 2020 · 1 comment
Open

请问如何限制链接允许连接的最多ip数量? #4

jakkpop opened this issue May 9, 2020 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@jakkpop
Copy link

jakkpop commented May 9, 2020

例如一个链接最多连接的ip数量为3

@skyxv skyxv self-assigned this May 9, 2020
@skyxv skyxv added the question Further information is requested label May 9, 2020
@skyxv
Copy link
Owner

skyxv commented May 9, 2020

最简单的方法就是在apps/urls/views.py下的RedirectView处理,在get方法中,使用redis的set结构,假设你要限制最多n个ip:

如果scard 短码 得到的数量小于n

则执行sadd 短码 ip 将新进来的ip加入短码为key的set中

否则,说明该短码已经绑定了n个ip, 则使用sismember查看当前进来的请求ip是否在该短码下,如果是,则允许跳转,反之则不跳转

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants