问题描述
客户反馈 Redisson 客户端无法使用非 Default 用户连接缓存数据库Redis,客户配置如下:
springboot redisson-spring-boot-starter
applicaiton.propertities 文件配置 spring.redis.password=username:password xxxxxxx
```
`
````undefined
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redission-spring-boot-starter</artifactId>
<version>3.12.5</version>
</dependency>
```
`
# 问题分析
1. 客户的使用的代码与火山缓存数据库 Redis 用户名密码认证格式不兼容,火山用户名和密码需要分开配置。
2. 对于 redisson,最低版本需要 3.16 才能提供用户名密码配置
# 解决方案
单独配置username和password参数,具体的参考application-settings.yaml文件示例如下:
```java
singleServerConfig:
idleConnectionTimeout: 10000
connectTimeout: 10000
timeout: 3000
retryAttempts: 3
retryInterval: 1500
username: demo
password: test****EWR
subscriptionsPerConnection: 5
clientName: null
address: "redis://redis-cn023ahm****.redis.volces.com:6379"
subscriptionConnectionMinimumIdleSize: 1
subscriptionConnectionPoolSize: 50
connectionMinimumIdleSize: 32
connectionPoolSize: 64
database: 0
dnsMonitoringInterval: 5000
threads: 0
nettyThreads: 0
```
Class 类文件示例如下
```java
package org.demos.redissondemo;
import java.io.File;
import java.io.IOException;
import org.redisson.Redisson;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
public class ClientDemo {
public static void main(String[] args) {
Config config = null;
try {
config = Config.fromYAML(new File("resources/application-settings.yaml"));
} catch (IOException e) {
e.printStackTrace();
}
RedissonClient redissonClient = Redisson.create(config);
RAtomicLong longObject = redissonClient.getAtomicLong("mylong1");
long value = longObject.get();
System.out.println("value: " + value);
}
}
```
# 参考文档
[1] [https://github.com/redisson/redisson](https://github.com/redisson/redisson)
**如果您有其他问题,欢迎您联系火山引擎**[技术支持服务](https://console.volcengine.com/ticket/createTicketV2/)