Преглед на файлове

Add method for getting TTL for redis entity

pull/11/head
Kristijan Mitrovic преди 4 години
родител
ревизия
17208b8f45
променени са 1 файла, в които са добавени 17 реда и са изтрити 0 реда
  1. +17
    -0
      wizard-server/src/main/java/org/cobbzilla/wizard/cache/redis/RedisService.java

+ 17
- 0
wizard-server/src/main/java/org/cobbzilla/wizard/cache/redis/RedisService.java Целия файл

@@ -118,6 +118,11 @@ public class RedisService {
public String get_withPrefix(String prefixedKey) { return decrypt(__get(prefixedKey, 0)); }
public String get_plaintext(String key) { return __get(prefix(key), 0); }

/**
* @param key
* @return TTL in seconds for the given key
*/
public int get_ttl(final String key) { return __ttl(prefix(key), 0).intValue(); }

public <T> void setObject(String key, T thing) { __set(prefix(key), encrypt(toJsonOrDie(thing)), 0); }
public void set(String key, String value) { __set(prefix(key), encrypt(value), 0); }
@@ -332,6 +337,18 @@ public class RedisService {
}
}

private Long __ttl(final String fullKey, final int attempt) {
try {
synchronized (redis) {
return getRedis().ttl(fullKey);
}
} catch (RuntimeException e) {
if (attempt > MAX_RETRIES) throw e;
resetForRetry(attempt, "retrying RedisService.__ttl");
return __ttl(fullKey, attempt + 1);
}
}

private boolean __exists(final String fullKey, final int attempt) {
try {
synchronized (redis) {


Зареждане…
Отказ
Запис