Added a field in JedisConstants for the selected Redis database.

This commit is contained in:
Nicholas Rees 2021-05-06 14:47:47 -05:00
parent 35641226a1
commit 184d6a2be4
4 changed files with 7 additions and 0 deletions

@ -6,4 +6,5 @@ package zone.themcgamer.data.jedis;
public class JedisConstants {
public static final String HOST = "172.18.0.1";
public static final String AUTH = "CWhsuGvpYPhZt7ru";
public static final int SELECTED_DB = 0;
}

@ -53,6 +53,7 @@ public class CacheRepository extends RedisRepository<String, ICacheItem<?>> {
List<ICacheItem<?>> cached = new ArrayList<>();
try (Jedis jedis = getController().getPool().getResource()) {
jedis.auth(JedisConstants.AUTH);
jedis.select(JedisConstants.SELECTED_DB);
for (ItemCacheType cacheType : ItemCacheType.values()) {
for (String key : jedis.keys(cacheType.getIdentifier() + ":*")) {
Map<String, String> map = jedis.hgetAll(key);

@ -35,6 +35,7 @@ public class JedisCommandHandler {
new Thread(() -> {
try (Jedis jedis = pool.getResource()) {
jedis.auth(JedisConstants.AUTH);
jedis.select(JedisConstants.SELECTED_DB);
jedis.psubscribe(new JedisPubSub() {
@Override
public void onPMessage(String pattern, String channel, String message) {
@ -80,6 +81,7 @@ public class JedisCommandHandler {
System.out.println("Dispatching Redis command for class \"" + className + "\" with json \"" + json + "\"");
try (Jedis jedis = pool.getResource()) {
jedis.auth(JedisConstants.AUTH);
jedis.select(JedisConstants.SELECTED_DB);
jedis.publish("mcGamerZone:commands:" + className, json);
}
}

@ -113,6 +113,7 @@ public abstract class RedisRepository<I, T> {
map.put(entry.getKey(), entry.getValue().toString());
try (Jedis jedis = controller.getPool().getResource()) {
jedis.auth(JedisConstants.AUTH);
jedis.select(JedisConstants.SELECTED_DB);
jedis.hmset(key, map);
long expiration = getExpiration(t);
@ -133,6 +134,7 @@ public abstract class RedisRepository<I, T> {
throw new IllegalArgumentException("Cannot remove, the key is null or empty: \"" + (key == null ? "null" : key) + "\"");
try (Jedis jedis = controller.getPool().getResource()) {
jedis.auth(JedisConstants.AUTH);
jedis.select(JedisConstants.SELECTED_DB);
jedis.del(key);
}
}
@ -147,6 +149,7 @@ public abstract class RedisRepository<I, T> {
List<T> cached = new ArrayList<>();
try (Jedis jedis = controller.getPool().getResource()) {
jedis.auth(JedisConstants.AUTH);
jedis.select(JedisConstants.SELECTED_DB);
Set<String> keys = jedis.keys(pattern);
for (String key : keys) {
Map<String, String> data = jedis.hgetAll(key);