Support TTL setting in 'lookup_set_value(lookup_table, key, value, ttl)'

This commit is contained in:
yo 2024-02-03 22:19:50 +01:00
parent 1873969cda
commit 5487e2dd71

View File

@ -156,17 +156,22 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
@Override
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();
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")) {
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();
return LookupResult.empty();
}
return LookupResult.single(value.toString());
} 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();
return LookupResult.empty();
} finally {