通过缓存减少数据库访问,提高访问速度
①.、redis官网 https://redis.io/download
简介:使用springboot-starter整合reids实战
# 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时spring.redis.pool.max-wait=1000
①.、注入模板@Autowiredprivate StirngRedisTemplate strTplRedis
package com.atguigu.springboot.controller; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.atguigu.springboot.controller.domain.JsonData; @RestController @RequestMapping("/api/v1/redis") public class RdisTestController { private StringRedisTemplate redisTpl; //jdbcTemplate @GetMapping(value="add") public Object add(){ //opsForValue : Returns the operations performed on simple values (or Strings in Redis terminology). redisTpl.opsForValue().set("name", "xdclass2018"); return JsonData.buildSuccess(); @GetMapping(value="get") public Object get(){ String value = redisTpl.opsForValue().get("name"); return JsonData.buildSuccess(value); }
controller
以上就是土嘎嘎小编为大家整理的【SpringBoot】整合Redis实战相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!