mirror of
https://github.com/qiurunze123/miaosha.git
synced 2023-11-19 22:41:03 +08:00
提交统计次数
This commit is contained in:
parent
f190d93e41
commit
26f5dcffba
|
@ -144,4 +144,4 @@
|
|||
|
||||
![整体流程](https://raw.githubusercontent.com/qiurunze123/imageall/master/count.png)
|
||||
|
||||
利用lua脚本进行对redis操作,写通用方法随时在某处进行统计详情请看redislua.class
|
||||
利用lua脚本进行对redis操作,登陆时,每次登陆成功则记录访问(具体你想在什么时段进行统计自己说了算)
|
|
@ -3,6 +3,9 @@ package com.geekq.miaosha.common;
|
|||
public class Constanst {
|
||||
public static String CLOSE_ORDER_INFO_TASK_LOCK = "CLOSE_ORDER_INFO_KEY";
|
||||
|
||||
public static String COUNTLOGIN = "count:login";
|
||||
|
||||
|
||||
public enum orderStaus{
|
||||
ORDER_NOT_PAY("新建未支付");
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static com.geekq.miaosha.common.Constanst.COUNTLOGIN;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/login")
|
||||
public class LoginController {
|
||||
|
@ -27,7 +29,7 @@ public class LoginController {
|
|||
@RequestMapping("/to_login")
|
||||
public String tologin(LoginVo loginVo, Model model) {
|
||||
logger.info(loginVo.toString());
|
||||
String count = RedisLua.getVistorCount().toString();
|
||||
String count = RedisLua.getVistorCount(COUNTLOGIN).toString();
|
||||
logger.info("访问网站的次数为:{}",count);
|
||||
model.addAttribute("count",count);
|
||||
return "login";
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RedisLua {
|
|||
/**
|
||||
* 统计访问次数
|
||||
*/
|
||||
public static Object getVistorCount() {
|
||||
public static Object getVistorCount(String key) {
|
||||
|
||||
Jedis jedis = null;
|
||||
Object object = null;
|
||||
|
@ -58,7 +58,7 @@ public class RedisLua {
|
|||
String count =
|
||||
"local num=redis.call('get',KEYS[1]) return num";
|
||||
List<String> keys = new ArrayList<String>();
|
||||
keys.add("count:login");
|
||||
keys.add(key);
|
||||
List<String> argves = new ArrayList<String>();
|
||||
jedis.auth("youxin11");
|
||||
String luaScript = jedis.scriptLoad(count);
|
||||
|
@ -74,7 +74,7 @@ public class RedisLua {
|
|||
/**
|
||||
* 统计访问次数
|
||||
*/
|
||||
public static void vistorCount() {
|
||||
public static void vistorCount(String key) {
|
||||
|
||||
Jedis jedis = null;
|
||||
Object object = null;
|
||||
|
@ -83,7 +83,7 @@ public class RedisLua {
|
|||
String count =
|
||||
"local num=redis.call('incr',KEYS[1]) return num";
|
||||
List<String> keys = new ArrayList<String>();
|
||||
keys.add("count:login");
|
||||
keys.add(key);
|
||||
List<String> argves = new ArrayList<String>();
|
||||
jedis.auth("youxin11");
|
||||
String luaScript = jedis.scriptLoad(count);
|
||||
|
@ -93,8 +93,4 @@ public class RedisLua {
|
|||
logger.error("统计访问次数失败!!!",e);
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
getVistorCount();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user