Ver código fonte

implement redis pexpire, use for confirmLock

tags/2.0.1
Jonathan Cobb 4 anos atrás
pai
commit
ac89c6341f
1 arquivos alterados com 14 adições e 1 exclusões
  1. +14
    -1
      wizard-server/src/main/java/org/cobbzilla/wizard/cache/redis/RedisService.java

+ 14
- 1
wizard-server/src/main/java/org/cobbzilla/wizard/cache/redis/RedisService.java Ver arquivo

@@ -154,6 +154,7 @@ public class RedisService {

public Long touch(String key) { return __touch(key, 0, MAX_RETRIES); }
public Long expire(String key, long ttl) { return __expire(key, (int) ttl, 0, MAX_RETRIES); }
public Long pexpire(String key, long ttl) { return __pexpire(key, (int) ttl, 0, MAX_RETRIES); }

public List<String> list(String key) { return lrange(key, 0, -1); }
public Long llen(String key) { return __llen(key, 0, MAX_RETRIES); }
@@ -243,7 +244,7 @@ public class RedisService {
key = key + LOCK_SUFFIX;
final String lockVal = get(key);
if (lockVal != null && lockVal.equals(lock)) {
expire(key, lockTimeout);
pexpire(key, lockTimeout);
return true;
}
return false;
@@ -469,6 +470,18 @@ public class RedisService {
}
}

private Long __pexpire(String key, long ttl, int attempt, int maxRetries) {
try {
synchronized (redis) {
return getRedis().pexpire(prefix(key), ttl);
}
} catch (RuntimeException e) {
if (attempt > maxRetries) throw e;
resetForRetry(attempt, "retrying RedisService.__pexpire");
return __pexpire(key, ttl, attempt+1, maxRetries);
}
}

private Long __lpush(String key, String value, int attempt, int maxRetries) {
try {
synchronized (redis) {


Carregando…
Cancelar
Salvar