Redis使用(二):SpringBoot整合Redis 配置文件及项目种简单应用

#redis配置
  redis:
    #数据库索引
    database: 0
    host: 127.0.0.1
    port: 6379
    password:xxx
    jedis:
      pool:
        #最大连接数
        max-active: 8
        #最大阻塞等待时间(负数表示没限制)
        max-wait: -1
        #最大空闲
        max-idle: 8
        #最小空闲
        min-idle: 0
    #连接超时时间
    timeout: 10000

Redis使用(二):SpringBoot整合Redis 配置文件及项目种简单应用_第1张图片
下面上代码:

	@Autowired
    private StringRedisTemplate stringRedisTemplate;
    //String 存取
    @RequestMapping(value = "select",method = RequestMethod.GET)
    List select(){
        String cacheKey = "employeeList";
        //获取key为。。。的List
        String employee =stringRedisTemplate.opsForValue().get(cacheKey);
        List employeeList=null;
        if (StringUtils.isEmpty(employee)){
            employeeList = employeeService.query();
            String list = JsonUtil.listToJson(employeeList);
            //存入值
            stringRedisTemplate.opsForValue().set(cacheKey,list,30, TimeUnit.HOURS);
            return employeeList;
        }
        List employeeList1 = JsonUtil.jsonToList(employee, Employee.class);
        return employeeList1;
    }

你可能感兴趣的:(热血,女屌丝)