一、下载安装redis
1.官网地址 https://redis.io/
2.GitHub地址:https://github.com/MicrosoftArchive/redis/tags
3.安装(自行安装)
二、SpringBoot集成redis
1.在pom.xml中添加依赖
<!-- 整合redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2.在application.properties配置文件中进行配置
# Redis配置
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=Qa123456
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=7200
3.编写controller进行测试
package com.yuewuhen.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
*@Author:赵涛
*@Date:2019/1/7 13:10
* 测试SpringBoot集成redis 使用StringRedisTemplate
*/
@RestController
@RequestMapping("/redis")
public class RedisStringController {
@Autowired
private StringRedisTemplate redisClient;
@RequestMapping("/getValue")
public String getValue(@RequestParam(name="key",required = true) String key,
@RequestParam(name="value",required = true)String value){
redisClient.opsForValue().set(key,value);
return redisClient.opsForValue().get(key);
}
}
4.测试(测试之前先启动redis服务)
如上图,使用postman测试成功,为了验证是否真的成功,启动命令行窗口,测试
成功。