Support TTL setting in 'lookup_set_value(lookup_table, key, value, ttl)'
This commit is contained in:
parent
1873969cda
commit
5487e2dd71
@ -156,17 +156,22 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LookupResult setValue(Object key, Object value) {
|
public LookupResult setValue(Object key, Object value) {
|
||||||
|
return setValueWithTtl(key, value, this.config.redisKeyTTL());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LookupResult setValueWithTtl(Object key, Object value, Long ttlSec) {
|
||||||
final Timer.Context time = redisSetRequestTimer.time();
|
final Timer.Context time = redisSetRequestTimer.time();
|
||||||
try {
|
try {
|
||||||
final String result = this.commands.setex(key.toString(), this.config.redisKeyTTL(), value.toString());
|
final String result = this.commands.setex(key.toString(), ttlSec, value.toString());
|
||||||
if (!result.equals("OK")) {
|
if (!result.equals("OK")) {
|
||||||
LOG.warn("Redis SET key <{}> to value <{}> returned {}", key, value, result);
|
LOG.warn("Redis SETEX key <{}> to value <{}> with TTL <{}> returned {}", key, value, ttlSec, result);
|
||||||
redisSetRequestErrors.mark();
|
redisSetRequestErrors.mark();
|
||||||
return LookupResult.empty();
|
return LookupResult.empty();
|
||||||
}
|
}
|
||||||
return LookupResult.single(value.toString());
|
return LookupResult.single(value.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Redis SET key <{}> to value <{}> returned an exception: {}", key, value, e);
|
LOG.error("Redis SETEX key <{}> to value <{}> with TTL <{}> returned an exception: {}", key, value, ttlSec, e);
|
||||||
redisSetRequestErrors.mark();
|
redisSetRequestErrors.mark();
|
||||||
return LookupResult.empty();
|
return LookupResult.empty();
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
Reference in New Issue
Block a user