forked from qiurunze123/miaosha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed68ca4
commit 1e79885
Showing
8 changed files
with
121 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/geekq/miaosha/controller/TestLuaController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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(); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/geekq/miaosha/redis/redismanager/RedisLua.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.geekq.miaosha.redis.redismanager; | ||
|
||
import redis.clients.jedis.Jedis; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class RedisLua { | ||
|
||
/** | ||
* 未完成 需 evalsha更方便 | ||
*/ | ||
public static void getLUa() { | ||
|
||
Jedis jedis = null; | ||
try { | ||
jedis = RedisManager.getJedis(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
String lua = | ||
"local num=redis.call('incr',KEYS[1]) if tonumber(num)==1 " + | ||
"then redis.call('expire',KEYS[1],ARGV[1]) " + | ||
"return 1 elseif tonumber(num)>" + | ||
"tonumber(ARGV[2]) then return 0 else return 1 end"; | ||
|
||
List<String> keys = new ArrayList<String>(); | ||
keys.add("ip:limit:127.0.0.1"); | ||
List<String> argves = new ArrayList<String>(); | ||
argves.add("6000"); | ||
argves.add("5"); | ||
jedis.auth("youxin11"); | ||
Object object = jedis.eval(lua, keys, argves); | ||
System.out.println(object); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,6 @@ public static Jedis getJedis() throws Exception{ | |
} | ||
throw new Exception("Jedispool was not init !!!"); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters