Skip to content

Commit

Permalink
Added redis auth support
Browse files Browse the repository at this point in the history
  • Loading branch information
QuickGlare committed Feb 24, 2021
1 parent ea033d0 commit a39e18e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.alerium.chocolate</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>

<modules>
<module>velocity</module>
Expand Down
2 changes: 1 addition & 1 deletion spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.alerium.chocolate</groupId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
</parent>

<artifactId>spigot</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.alerium.chocolate</groupId>
<artifactId>parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
</parent>

<artifactId>velocity</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class RedisManager {

private PubSubListener psListener;

private String redisPassword;
@Getter private String proxyName;
@Getter private int onlinePlayers;

Expand All @@ -30,6 +31,7 @@ public class RedisManager {
*/
public void enable() {
JsonObject redisConfig = plugin.getConfig().getObject().getAsJsonObject("redis");
redisPassword = redisConfig.has("password") ? redisConfig.get("password").getAsString() : null;
pool = new JedisPool(new JedisPoolConfig(), redisConfig.get("hostname").getAsString(), redisConfig.get("port").getAsInt());

psListener = new PubSubListener(plugin);
Expand Down Expand Up @@ -192,7 +194,10 @@ public void unregisterChannel(String... channels) {
}

private Jedis getConnection() {
return pool.getResource();
Jedis jedis = pool.getResource();
if (redisPassword != null && !redisPassword.isEmpty())
jedis.auth(redisPassword);
return jedis;
}

}
3 changes: 2 additions & 1 deletion velocity/src/main/resources/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"redis": {
"hostname": "localhost",
"port": 6379
"port": 6379,
"password": ""
},

"proxyName": "proxy1",
Expand Down

0 comments on commit a39e18e

Please sign in to comment.