簡介
spring boot版本為2.1.5.RELEASE
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2. properties配置檔案配置redis資訊
預設連線本地6379埠的redis服務,一般需要修改配置,例如:
# Redis資料庫索引(預設為0)
spring.redis.database=0
# Redis伺服器地址
spring.redis.host=127.0.0.1
# Redis伺服器連線埠
spring.redis.port=6379
# Redis伺服器連線密碼(預設為空)
spring.redis.password=
# 連線池最大連線數(使用負值表示沒有限制)
spring.redis.jedis.pool.max-active=20
# 連線池最大阻塞等待時間(使用負值表示沒有限制)
spring.redis.jedis.pool.max-wait=-1
# 連線池中的最大空閒連線
spring.redis.jedis.pool.max-idle=10
# 連線池中的最小空閒連線
spring.redis.jedis.pool.min-idle=0
# 連線超時時間(毫秒)
spring.redis.timeout=1000
3. redis配置類
@Bean public RedisTemplate redisTemplate(JedisConnectionFactory jedisConnectionFactory) { RedisTemplate template = new RedisTemplate (); template.setConnectionFactory(jedisConnectionFactory); return template; }
Redis和springboot結合一般使用多個redis負載均衡,這樣那有效保證資料的完整,系統的有效執行。
簡介
spring boot版本為2.1.5.RELEASE
SpringBoot 配置Redispom 引入spring-boot-starter-data-redis 包<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2. properties配置檔案配置redis資訊
預設連線本地6379埠的redis服務,一般需要修改配置,例如:
# Redis資料庫索引(預設為0)
spring.redis.database=0
# Redis伺服器地址
spring.redis.host=127.0.0.1
# Redis伺服器連線埠
spring.redis.port=6379
# Redis伺服器連線密碼(預設為空)
spring.redis.password=
# 連線池最大連線數(使用負值表示沒有限制)
spring.redis.jedis.pool.max-active=20
# 連線池最大阻塞等待時間(使用負值表示沒有限制)
spring.redis.jedis.pool.max-wait=-1
# 連線池中的最大空閒連線
spring.redis.jedis.pool.max-idle=10
# 連線池中的最小空閒連線
spring.redis.jedis.pool.min-idle=0
# 連線超時時間(毫秒)
spring.redis.timeout=1000
3. redis配置類
@Bean public RedisTemplate redisTemplate(JedisConnectionFactory jedisConnectionFactory) { RedisTemplate template = new RedisTemplate (); template.setConnectionFactory(jedisConnectionFactory); return template; }
總結Redis和springboot結合一般使用多個redis負載均衡,這樣那有效保證資料的完整,系統的有效執行。