Redis学习记录------SpringBoot整合Redis(七)-未完待续
Redis学习记录------SpringBoot整合Redis(七)
引入两个依赖
<!--redis--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.7.3</version> </dependency> <!--Spring2.X集成redis所需要common-pools--> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> <version>2.6.2</version> </dependency> </dependencies>
配置文件:application.properties
#Redis 服务器地址: spring.redis.host=192.168.140.136 #Redis 服务器端口号: spring.redis.port=6379 #Redis 服务器数据库索引,默认0: spring.redis.database=0 #Redis 超时时间(毫秒): spring.redis.timeout=1800000 #Redis 连接池最大连接数,使用负值代表没有限制: spring.redis.lettuce.pool.max-active=20 #Redis 最大阻塞等待时间(负数表示没有限制): spring.redis.lettuce.pool.max-wait=-1 #Redis 连接池中最大空闲连接: spring.redis.lettuce.pool.max-idle=5 #Redis 最小空闲连接: spring.redis.lettuce.pool.min-idle=0
需创建RedisTemplate类,测试时自动注入该模板类即可使用,与JDBCTemplate差不多。