Skip to content

Properly set password for Redis Sentinel/Cluster configurations. - #9583

Closed
zhujk wants to merge 1 commit into
spring-projects:masterfrom
zhujk:master
Closed

zhujk wants to merge 1 commit into
spring-projects:masterfrom
zhujk:master

Conversation

@zhujk

@zhujk zhujk commented Jun 23, 2017

Copy link
Copy Markdown

Set password for RedisSentinelConfiguration and RedisClusterConfiguration.

Since 2.0, configure the password using RedisStandaloneConfiguration, RedisSentinelConfiguration or RedisClusterConfiguration as described in the documentation.

In 2.0.0.M2,however,only RedisStandaloneConfiguration set the password property.
The test is as follows:

  1. application.yml
spring:
  redis:
    cluster:
      nodes: ******
    password: ******
  1. AppApplicationTests.kt
@RunWith(SpringRunner::class)
@SpringBootTest
class AppApplicationTests {
    @Autowired
    lateinit var stringRedisTemplate: StringRedisTemplate

    @Test
    fun contextLoads() {
        val valueOperations = stringRedisTemplate.opsForValue()
        valueOperations.set("foo", "bar")
        then(valueOperations.get("foo")).isEqualTo("bar")
    }
}
  1. error

i.l.c.c.topology.ClusterTopologyRefresh : Cannot retrieve partition view from RedisURI [host='**', port=], error: java.util.concurrent.ExecutionException: io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.

While it's OK in version 2.0.0.M1. I have to declare a bean in AppApplicationTests then it works.

  1. declare redisClusterConfiguration bean.
@RunWith(SpringRunner::class)
@SpringBootTest
class AppApplicationTests {
    @Autowired
    lateinit var stringRedisTemplate: StringRedisTemplate

    @TestConfiguration
    class Config {
        @Bean
        fun redisClusterConfiguration(redisProperties: RedisProperties) =
                RedisClusterConfiguration(redisProperties.cluster.nodes).apply {
                    redisProperties.cluster.maxRedirects?.let { maxRedirects = it }
                    redisProperties.password?.let { password = RedisPassword.of(it) }
                }
    }

    @Test
    fun contextLoads() {
        val valueOperations = stringRedisTemplate.opsForValue()
        valueOperations.set("foo", "bar")
        then(valueOperations.get("foo")).isEqualTo("bar")
    }

}

So it will be better without having to declare the bean.

RedisSentinelConfiguration & RedisClusterConfiguration.
Signed-off-by: zhujk <[email protected]>
@pivotal-issuemaster

Copy link
Copy Markdown

@zhujk Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster

Copy link
Copy Markdown

@zhujk Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Jun 23, 2017
@snicoll snicoll added type: regression A regression from a previous release priority: high and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Jun 24, 2017
@snicoll snicoll self-assigned this Jun 24, 2017
@snicoll snicoll added this to the 2.0.0.M3 milestone Jun 24, 2017
@snicoll

snicoll commented Jun 24, 2017

Copy link
Copy Markdown
Member

Oops, good catch. We should add more tests because some should have covered us when we did the refactoring. I discussed with @mp911de about it unless you want to give that a try?

@snicoll snicoll closed this in 557361c Jun 27, 2017
@snicoll

snicoll commented Jun 27, 2017

Copy link
Copy Markdown
Member

Thanks for the PR, I went ahead with that change adding tests in the process.

@snicoll snicoll changed the title set password for redis configurations Properly set password for Redis Sentinel/Cluster configurations. Jun 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: regression A regression from a previous release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants