springboot使用redis作session缓存

springboot 2.5.1 使用Redis作为缓存

我用的是 springboot 2.5.1

  1. 在 https://start.spring.io/ 官方添加这两个依赖
    在这里插入图片描述
    或者
    直接在pom.xml文件添加依赖
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-redis</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.session</groupId>
			<artifactId>spring-session-data-redis</artifactId>
		</dependency>
  1. 写配置文件
spring:
  redis:
    host: localhost
    password: 123456
  session:
    store-type: redis
    timeout: 1800 #30分钟 30x60

好,大功告成。
同时 redis 缓存也可以拿来自己用

	@Autowired
	private StringRedisTemplate redisTemplete;

版权声明:本文为weixin_44485192原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。