首先安装好redis, 本地开发测试,建议安装 windows绿色版本的redis

配置pom, 在相应服务的pom中添加

<!--SpringDataRedis的启动器--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

2.application.properties 配置文件中配置

#===========Redis配置===========fromwww.1b23.com#Redis数据库索引(默认为0)spring.redis.database=0#Redis服务器地址spring.redis.host=127.0.0.1#Redis服务器连接端口spring.redis.port=6379#Redis服务器连接密码(默认为空)spring.redis.password=root#连接池最大连接数(使用负值表示没有限制)spring.redis.pool.max-active=200#连接池最大阻塞等待时间(使用负值表示没有限制)spring.redis.pool.max-wait=-1#连接池中的最大空闲连接spring.redis.pool.max-idle=10#连接池中的最小空闲连接spring.redis.pool.min-idle=0#连接超时时间(毫秒)spring.redis.timeout=2000msspring.redis.jedis.pool.max-wait=-1ms#===========Redis配置===========

3.启动类上加上注解

@EnableRedisHttpSession


读取和写入session 和 普通方式一样