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

看了下项目里的lua脚本,这是令牌桶算法吗? #4

Open
CaiusBallad opened this issue Feb 7, 2021 · 0 comments
Open

Comments

@CaiusBallad
Copy link

private String buildLuaScript() {
    StringBuilder lua = new StringBuilder();
    lua.append( " local key = KEYS[1]" );
    lua.append( "\nlocal limit = tonumber(ARGV[1])" );
    lua.append( "\nlocal curentLimit = tonumber(redis.call('get', key) or \"0\")" );
    lua.append( "\nif curentLimit + 1 > limit then" );
    lua.append( "\nreturn 0" );
    lua.append( "\nelse" );
    lua.append( "\n redis.call(\"INCRBY\", key, 1)" );
    lua.append( "\nredis.call(\"EXPIRE\", key, ARGV[2])" );
    lua.append( "\nreturn curentLimit + 1" );
    lua.append( "\nend" );
    return lua.toString();
}

设置了redis的过期时间,这本质上还是计数器算法吧?

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