《SpringBoot2.X心法总纲》redis
简介:单机redis+springboot,并非jedis单机操做redis,jedis是须要另外的集成,下一篇博客会讲到。spring
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
spring.redis.database=0 spring.redis.host=localhost spring.redis.port=6379 spring.redis.password= spring.redis.timeout=10000ms
2.0以后须要加ms参数才能够,否则报错,因此之后找2.0博客,标题说是springboot 2.0,可是内容依然是spring.redis.timeout=10000后面没有加ms的都是1.X版本,博客都不是很严格。数据库
@RestController public class TestController { @Autowired StringRedisTemplate stringRedisTemplate; @RequestMapping(value = "/redis/test1") public String getOne(){ ValueOperations<String,String> operations = stringRedisTemplate.opsForValue(); operations.set("mjt","测试redis添加"); String result = operations.get("mjt"); return result; } }
只须要写一个controller就好,而后咱们启动springboot,调用接口成功!springboot
纯本身单机使用redis,用来掌握RedisTemplate操做数据库的,可是开发不是下面这简单的配置,配置文件中也没有使用相似于 spring.redis.jedis.pool.max-active=8 这样的配置,那么下一篇会讲解。app