-
redis-sb-demo02:pom.xml中添加redis坐标
org.springframework.boot spring-boot-starter-data-redis -
配置信息
######################################################## ###REDIS (RedisProperties) redis基本配置; ######################################################## # database name spring.redis.database=0 # server host1 spring.redis.host=127.0.0.1 # server password #spring.redis.password= #connection port spring.redis.port=6379 # pool settings ... spring.redis.jedis.pool.max-idle=8 spring.redis.jedis.pool.min-idle=0 spring.redis.jedis.pool.max-active=8 spring.redis.jedis.pool.max-wait=-1 # name of Redis server #spring.redis.sentinel.master= # comma-separated list of host:port pairs #spring.redis.sentinel.nodes=
-
当SpringBoot整合SpringDataRedis之后,我们使用的对象的是RedisTemplate
第一步:pom
org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-data-redis org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine
第二步:创建UserController类
package com.youpingou.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class UserController {
//只需要导入springboot-data-redis的启动器,就可以使用当前这个目标,所有的初始化都由Spring帮你完成
@Autowired
private StringRedisTemplate stringRedisTemplate;
@GetMapping
public ResponseEntity
第三步:启动测试,ok



