登录增加限流控制

This commit is contained in:
none
2023-03-10 14:24:36 +08:00
parent f9dec16760
commit 81870bd802
7 changed files with 88 additions and 5 deletions

View File

@@ -0,0 +1,32 @@
package xyz.playedu.api.caches;
import org.springframework.stereotype.Component;
import xyz.playedu.api.exception.LimitException;
import xyz.playedu.api.util.RedisUtil;
/**
* @Author 杭州白书科技有限公司
* @create 2023/3/10 14:13
*/
@Component
public class UserLoginCache {
private final static String keyTemplate = "user-login:%s";
private final static int expire = 10;//10s
public void check(String email) throws LimitException {
if (RedisUtil.exists(key(email))) {
throw new LimitException();
}
}
public void put(String email) {
RedisUtil.set(key(email), "1", expire);
}
private String key(String email) {
return String.format(keyTemplate, email);
}
}