Skip to content

Commit d64f723

Browse files
committed
feat: add redis username support
1 parent 56e7cb4 commit d64f723

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Aggregate data across multiple servers using Redis. Perfect for server networks
6363
"Redis": {
6464
"Host": "redis.example.com",
6565
"Port": 6379,
66+
"Username": "optional",
6667
"Password": "optional",
6768
"Database": 0,
6869
"UseTLS": false
@@ -81,7 +82,8 @@ Aggregate data across multiple servers using Redis. Perfect for server networks
8182
| `Store.Type` | `"redis"` | Storage backend type (only `redis` supported) |
8283
| `Store.Redis.Host` | `"localhost"` | Redis server hostname |
8384
| `Store.Redis.Port` | `6379` | Redis server port |
84-
| `Store.Redis.Password` | `null` | Redis password (optional) |
85+
| `Store.Redis.Username` | `null` | Redis username for ACL auth (Redis 6+) |
86+
| `Store.Redis.Password` | `null` | Redis password |
8587
| `Store.Redis.Database` | `0` | Redis database number |
8688
| `Store.Redis.UseTLS` | `false` | Enable TLS/SSL connection |
8789

@@ -279,10 +281,13 @@ All fields are optional. When not set, actual server values are used.
279281
```json
280282
{
281283
"Enabled": true,
282-
"LegacyProtocolEnabled": false,
284+
"LegacyProtocolEnabled": true,
283285
"ServerInfo": {
284286
"ServerName": "My Network",
285-
"Host": "play.mynetwork.com"
287+
"Motd": "Welcome to our server!",
288+
"Host": "play.mynetwork.com",
289+
"Port": 5520,
290+
"MaxPlayers": 1000
286291
},
287292
"Authentication": {
288293
"Public": {
@@ -305,8 +310,16 @@ All fields are optional. When not set, actual server values are used.
305310
"Type": "redis",
306311
"Redis": {
307312
"Host": "redis.mynetwork.com",
308-
"Port": 6379
313+
"Port": 6379,
314+
"Username": "default",
315+
"Password": "secret",
316+
"Database": 0,
317+
"UseTLS": false
309318
}
319+
},
320+
"Timing": {
321+
"HeartbeatIntervalSeconds": 15,
322+
"CacheRefreshSeconds": 60
310323
}
311324
},
312325
"ServerList": {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<version>${revision}</version>
1010

1111
<properties>
12-
<revision>2.0.0-SNAPSHOT</revision>
12+
<revision>2.0.1-SNAPSHOT</revision>
1313
<maven.compiler.source>21</maven.compiler.source>
1414
<maven.compiler.target>21</maven.compiler.target>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/dev/hytaleone/query/config/NetworkConfig.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ public static class RedisConfig {
209209
(o, v) -> o.host = v, o -> o.host)
210210
.addField(new KeyedCodec<>("Port", Codec.INTEGER),
211211
(o, v) -> o.port = v, o -> o.port)
212+
.addField(new KeyedCodec<>("Username", Codec.STRING),
213+
(o, v) -> o.username = v, o -> o.username)
212214
.addField(new KeyedCodec<>("Password", Codec.STRING),
213215
(o, v) -> o.password = v, o -> o.password)
214216
.addField(new KeyedCodec<>("Database", Codec.INTEGER),
@@ -219,6 +221,7 @@ public static class RedisConfig {
219221

220222
private String host = "localhost";
221223
private int port = 6379;
224+
private String username = null;
222225
private String password = null;
223226
private int database = 0;
224227
private boolean useTLS = false;
@@ -243,6 +246,15 @@ public void setPort(int port) {
243246
this.port = port;
244247
}
245248

249+
@Nullable
250+
public String getUsername() {
251+
return username;
252+
}
253+
254+
public void setUsername(@Nullable String username) {
255+
this.username = username;
256+
}
257+
246258
@Nullable
247259
public String getPassword() {
248260
return password;
@@ -275,7 +287,9 @@ public void setUseTLS(boolean useTLS) {
275287
public String toRedisUri() {
276288
StringBuilder sb = new StringBuilder();
277289
sb.append(useTLS ? "rediss://" : "redis://");
278-
if (password != null && !password.isEmpty()) {
290+
if (username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
291+
sb.append(username).append(":").append(password).append("@");
292+
} else if (password != null && !password.isEmpty()) {
279293
sb.append(":").append(password).append("@");
280294
}
281295
sb.append(host).append(":").append(port);

0 commit comments

Comments
 (0)