Browse Source

Add method for getting TTL for redis entity

pull/11/head
Kristijan Mitrovic 4 years ago
parent
commit
17208b8f45
1 changed files with 17 additions and 0 deletions
  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 View File

@@ -118,6 +118,11 @@ public class RedisService {
public String get_withPrefix(String prefixedKey) { return decrypt(__get(prefixedKey, 0)); } public String get_withPrefix(String prefixedKey) { return decrypt(__get(prefixedKey, 0)); }
public String get_plaintext(String key) { return __get(prefix(key), 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 <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); } 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) { private boolean __exists(final String fullKey, final int attempt) {
try { try {
synchronized (redis) { synchronized (redis) {


Loading…
Cancel
Save