GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp
Update docs for Memorystore for Redis Cluster
- Dominant language
- Java
- Stars
- 551
- Forks
- 349
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
The [docs for Memorystore for Redis](https://googlecloudplatform.github.io/spring-cloud-gcp/6.2.3/reference/html/index.html#cloud-memorystore-for-redis) currently only detail how to connect to Redis Instance. Not all of this applies if you're using Memorystore for Redis Cluster, and some of it can even be harmful if used directly combined with Redis Cluster. Perhaps there could also be extended support in code.
In case of Redis Cluster, there are some differences.
### Specify cluster discovery node:
If you do not do this but use the regular host/port properties, you'll end up with a single connection to a specific node and there is nothing to warn you about that. Very easy mistake to make.
```yaml
spring:
data:
redis:
cluster:
nodes:
- 10.210.44.3:6379
```
### Auth
Afaik the AUTH string as used by Memorystore for Redis Instance setup does not apply to Redis cluster. We've had to do some manual configuration to pass the access token to the connection:
```java
@Configuration
public class RedisConfig {
@Bean
public LettuceClientConfigurationBuilderCustomizer lettuceClientConfigurationBuilderCustomizer() {
return builder -> builder.redisCredentialsProviderFactory(new RedisCredentialsProviderFactory() {
@Override
public RedisCredentialsProvider createCredentialsProvider(RedisConfiguration redisConfiguration) {
return () -> Mono.just(RedisCredentials.just("default", retrieveAccessToken()));
}
});
}
private char[] retrieveAccessToken() throws IOException {
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
.createScoped("https://www.googleapis.com/auth/cloud-platform");
credentials.refreshIfExpired();
return credentials.getAccessToken().getTokenValue().toCharArray();
}
}
```
This feels like a nice opportunity for some auto-configuration, or at least support for using `CredentialsProvider`.
Contributor guide
Assessment
This issue has not been assessed yet.