springboot整合redis

笔记

简介:使用springboot-starter整合reids实战

	1、官网:https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-redis
		集群文档:https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#cluster

	2、springboot整合redis相关依赖引入
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
    
    3、相关配置文件配置
		#=========redis基础配置=========
		spring.redis.database=0
		spring.redis.host=127.0.0.1
		spring.redis.port=6379
		# 连接超时时间 单位 ms(毫秒)
		spring.redis.timeout=3000

		#=========redis线程池设置=========
		# 连接池中的最大空闲连接,默认值也是8。
		spring.redis.jedis.pool.max-idle=200

		#连接池中的最小空闲连接,默认值也是0。
		spring.redis.jedis.pool.min-idle=200

		# 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时
		spring.redis.jedis.pool.max-wait=1000



	4、常见redistemplate种类讲解和缓存实操(使用自动注入)

		1、注入模板
		@Autowired
		private StirngRedisTemplate strTplRedis

		2、类型String,List,Hash,Set,ZSet
		对应的方法分别是opsForValue()、opsForList()、opsForHash()、opsForSet()、opsForZSet()

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