Skip to content

Commit

Permalink
提交lua限流
Browse files Browse the repository at this point in the history
  • Loading branch information
qiurunze committed Dec 21, 2018
1 parent 6f5e3c8 commit eefe5ce
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
2 changes: 2 additions & 0 deletions docs/redis-good.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
return 1
end



**Redis(2.6以后)--lua--EVALSHA命令**

考虑到我们通过eval执行lua脚本,脚本比较长的情况下,每次调用脚本都需要把整个脚本传给redis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class LoginController {

@RequestMapping("/to_login")
public String tologin(LoginVo loginVo) {
RedisLua.getLUa();
logger.info(loginVo.toString());
return "login";
}
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/com/geekq/miaosha/controller/TestLuaController.java

This file was deleted.

14 changes: 10 additions & 4 deletions src/main/java/com/geekq/miaosha/redis/redismanager/RedisLua.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import java.util.ArrayList;
import java.util.List;

/**
* lua脚本使用
*/
public class RedisLua {

/**
* 未完成 需 evalsha更方便
* 未完成 需 evalsha更方便 限制ip 或者 手机号访问次数
*/
public static void getLUa() {
public static void getLuaLimit() {

Jedis jedis = null;
try {
Expand All @@ -29,8 +32,11 @@ public static void getLUa() {
List<String> argves = new ArrayList<String>();
argves.add("6000");
argves.add("5");
jedis.auth("youxin11");
Object object = jedis.eval(lua, keys, argves);
jedis.auth("xxxx");
// Object evalSha = jedis.evalsha(lua);
String luaScript = jedis.scriptLoad(lua);
System.out.println(luaScript);
Object object = jedis.evalsha(luaScript, keys, argves);
System.out.println(object);
}
}
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mybatis.config-locations=classpath:mybatis/config.xml
#datasource
spring.datasource.url=jdbc:mysql://39.107.245.253:3306/miaosha?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=xxxx
spring.datasource.password=nihaoma
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#druid
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
Expand Down Expand Up @@ -49,7 +49,7 @@ spring.resources.static-locations=classpath:/static/
redis.host=39.107.245.253
redis.port=6379
redis.timeout=100
redis.password=XXXX
redis.password=youxin11
redis.poolMaxTotal=1000
redis.poolMaxIdle=500
redis.poolMaxWait=500
Expand Down

0 comments on commit eefe5ce

Please sign in to comment.