Redis学习记录------SpringBoot整合Redis(七)-未完待续

小咪咪 2024-04-08 12:57 111阅读 0赞

Redis学习记录———SpringBoot整合Redis(七)

引入两个依赖

  1. <!--redis-->
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-data-redis</artifactId>
  5. <version>2.7.3</version>
  6. </dependency>
  7. <!--Spring2.X集成redis所需要common-pools-->
  8. <dependency>
  9. <groupId>org.apache.commons</groupId>
  10. <artifactId>commons-pool2</artifactId>
  11. <version>2.6.2</version>
  12. </dependency>
  13. </dependencies>

配置文件:application.properties

  1. #Redis 服务器地址:
  2. spring.redis.host=192.168.140.136
  3. #Redis 服务器端口号:
  4. spring.redis.port=6379
  5. #Redis 服务器数据库索引,默认0:
  6. spring.redis.database=0
  7. #Redis 超时时间(毫秒):
  8. spring.redis.timeout=1800000
  9. #Redis 连接池最大连接数,使用负值代表没有限制:
  10. spring.redis.lettuce.pool.max-active=20
  11. #Redis 最大阻塞等待时间(负数表示没有限制):
  12. spring.redis.lettuce.pool.max-wait=-1
  13. #Redis 连接池中最大空闲连接:
  14. spring.redis.lettuce.pool.max-idle=5
  15. #Redis 最小空闲连接:
  16. spring.redis.lettuce.pool.min-idle=0

需创建RedisTemplate类,测试时自动注入该模板类即可使用,与JDBCTemplate差不多。

发表评论

表情:
评论列表 (有 0 条评论,111人围观)

还没有评论,来说两句吧...

相关阅读