DataHandler.java getKeysAll
This commit is contained in:
parent
106efc3ed8
commit
75d89e7974
2 changed files with 33 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
package me.unurled.sacredrealms.sr.data;
|
package me.unurled.sacredrealms.sr.data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@ -35,4 +36,11 @@ public interface DataHandler {
|
||||||
* @return If the key exists
|
* @return If the key exists
|
||||||
*/
|
*/
|
||||||
boolean exists(@NotNull String key);
|
boolean exists(@NotNull String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all keys from the data source
|
||||||
|
*
|
||||||
|
* @return All keys
|
||||||
|
*/
|
||||||
|
List<String> getKeysAll(@NotNull String key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,13 @@ package me.unurled.sacredrealms.sr.data;
|
||||||
|
|
||||||
import static me.unurled.sacredrealms.sr.utils.Logger.error;
|
import static me.unurled.sacredrealms.sr.utils.Logger.error;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import me.unurled.sacredrealms.sr.SR;
|
import me.unurled.sacredrealms.sr.SR;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import redis.clients.jedis.JedisPooled;
|
import redis.clients.jedis.JedisPooled;
|
||||||
|
import redis.clients.jedis.params.ScanParams;
|
||||||
|
import redis.clients.jedis.resps.ScanResult;
|
||||||
|
|
||||||
public class Redis implements DataHandler {
|
public class Redis implements DataHandler {
|
||||||
|
|
||||||
|
@ -69,4 +73,25 @@ public class Redis implements DataHandler {
|
||||||
public boolean exists(@NotNull String key) {
|
public boolean exists(@NotNull String key) {
|
||||||
return client.exists(key);
|
return client.exists(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all keys from the data source
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @return All keys
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> getKeysAll(@NotNull String key) {
|
||||||
|
String cursor = "0";
|
||||||
|
ScanParams params = new ScanParams().match(key);
|
||||||
|
List<String> keys = new ArrayList<>();
|
||||||
|
|
||||||
|
do {
|
||||||
|
ScanResult<String> result = client.scan(cursor, params);
|
||||||
|
cursor = result.getCursor();
|
||||||
|
keys.addAll(result.getResult());
|
||||||
|
} while (!cursor.equals("0"));
|
||||||
|
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue