Open CaiusBallad opened 3 years ago
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的过期时间,这本质上还是计数器算法吧?
设置了redis的过期时间,这本质上还是计数器算法吧?