redis 并发测试安全测试代码

package com.jd.ng.shiro.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @Author: husToy.Wang
* @Date: 2019/7/1 9:07
* @Version 1.0
*/
@RestController
@RequestMapping(value = "/redis/info")
public class RedissionController {

@Autowired
private RedisTemplate redisTemplate;

private static final Logger logger = LoggerFactory.getLogger(RedissionController.class);


/**
* 对于redis设置安全进行压测
*/
@GetMapping
public void setMessage() {

Object k = redisTemplate.opsForValue().get("k");

try {

if (k == null){

redisTemplate.opsForValue().set("k",1 );
//logger.info("xxxxxxxx");
} else{
int b = (int)k;
redisTemplate.opsForValue().set("k", b+1 );
System.out.println(k);
}

}catch (Exception e){
logger.error("处理异常..............{}",e.getMessage());
}





}











}
posted @ 2019-07-01 10:34  雷神约  阅读(604)  评论(0编辑  收藏  举报