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());        }    }}
相關文章
相關標籤/搜索