提交lua限流

This commit is contained in:
qiurunze 2018-12-21 10:13:41 +08:00
parent 6f5e3c846d
commit eefe5ce077
5 changed files with 14 additions and 25 deletions

View File

@ -132,6 +132,8 @@
return 1
end
**Redis2.6以后)--lua--EVALSHA命令**
考虑到我们通过eval执行lua脚本,脚本比较长的情况下,每次调用脚本都需要把整个脚本传给redis

View File

@ -25,7 +25,6 @@ public class LoginController {
@RequestMapping("/to_login")
public String tologin(LoginVo loginVo) {
RedisLua.getLUa();
logger.info(loginVo.toString());
return "login";
}

View File

@ -1,18 +0,0 @@
package com.geekq.miaosha.controller;
import com.geekq.miaosha.redis.redismanager.RedisLua;
import com.geekq.miaosha.vo.LoginVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/lua")
public class TestLuaController {
@RequestMapping("/testlua")
public void lua() {
RedisLua.getLUa();
}
}

View File

@ -5,12 +5,15 @@ import redis.clients.jedis.Jedis;
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 {
@ -29,8 +32,11 @@ public class RedisLua {
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);
}
}

View File

@ -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
@ -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