You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
想要使用ip作为key,就会比较麻烦。customKeyFunction只能获取当前实例的方法且必须方法名称与传入参数一致,对于多种不同参数请求,就比较麻烦了。最后使用了keys = "T(hy.jtt808.ratelimit.RequestUtils).getClientIP()"
`
public class RequestUtils {
public static String getClientIP() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes == null) {
return "UNKNOWN";
}
HttpServletRequest request = attributes.getRequest();
String ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
}
`
The text was updated successfully, but these errors were encountered:
redis如果是无密码,配置文件必须将密码字段不能使用空字符串字段,会导致redis无法连接。
想要使用ip作为key,就会比较麻烦。customKeyFunction只能获取当前实例的方法且必须方法名称与传入参数一致,对于多种不同参数请求,就比较麻烦了。最后使用了keys = "T(hy.jtt808.ratelimit.RequestUtils).getClientIP()"
`
public class RequestUtils {
public static String getClientIP() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes == null) {
return "UNKNOWN";
}
}
}
`
The text was updated successfully, but these errors were encountered: