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

使用过程中的问题和经验,供大家参考 #8

Open
DanielZhao1990 opened this issue Jan 25, 2024 · 0 comments
Open

使用过程中的问题和经验,供大家参考 #8

DanielZhao1990 opened this issue Jan 25, 2024 · 0 comments

Comments

@DanielZhao1990
Copy link

  1. redis如果是无密码,配置文件必须将密码字段不能使用空字符串字段,会导致redis无法连接。

  2. 想要使用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;
    

    }
    }
    `

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

No branches or pull requests

1 participant