下面列出了org.springframework.boot.autoconfigure.data.redis.RedisProperties#getPort ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* spring boot 2.0后采用Lettuce作为redis调用客户端
* 默认配置只支持单机模式,如需要其他模式,需要另外定义
*
* @return LettuceConnectionFactory
*/
@Bean
@ConditionalOnMissingBean(type = {"org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory"})
public LettuceConnectionFactory redisConnectionFactory(RedisProperties redisProperties) {
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(redisProperties.getHost(),
redisProperties.getPort());
configuration.setDatabase(redisProperties.getDatabase());
configuration.setPassword(RedisPassword.of(redisProperties.getPassword()));
return new LettuceConnectionFactory(configuration);
}
@Bean
ReactiveRedisConnectionFactory reactiveRedisConnectionFactory(RedisProperties redisProperties) {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(redisProperties.getHost(), redisProperties.getPort());
redisStandaloneConfiguration.setPassword(redisProperties.getPassword());
return new LettuceConnectionFactory(redisStandaloneConfiguration);
}