Minor fixes so this compile

This commit is contained in:
yo000 2024-02-04 10:40:25 +01:00
parent f1c53077a4
commit 30e1bf70d9

View File

@ -100,20 +100,19 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
this.redisSetRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisSetRequestErrors"));
}
// Add code to initialise Redis connection
@Override
protected void doStart() throws Exception {
connection = this.client.connect();
this.commands = connection.sync();
}
// Add code to close Redis connection
@Override
protected void doStop() throws Exception {
connection.close();
client.close();
}
// Returns the refresh interval for this data adapter. Use {@link Duration#ZERO} if refresh should be disabled.
@Override
public Duration refreshInterval() {
return REFRESH_INTERVAL_DURATION;
@ -136,7 +135,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
try {
final String value = this.commands.get(trimmedKey);
if (value == null) {
LOG.warn("Redis GET request for key <{}> returned null, key do not exists.", trimmedKey);
LOG.debug("Redis GET request for key <{}> returned null, key do not exists.", trimmedKey);
redisGetRequestErrors.mark();
return LookupResult.empty();
}
@ -151,7 +150,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
}
// This is deprecated, see setValue
@Override
@Deprecated
public void set(Object key, Object value) {
return;
}
@ -161,7 +160,6 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
return setValueWithTtl(key, value, this.config.redisKeyTTL());
}
@Override
public LookupResult setValueWithTtl(Object key, Object value, Long ttlSec) {
final Timer.Context time = redisSetRequestTimer.time();
final String trimmedKey = StringUtils.trimToNull(key.toString());
@ -176,7 +174,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
} catch (Exception e) {
LOG.error("Redis SETEX key <{}> to value <{}> with TTL <{}> returned an exception: {}", key, value, ttlSec, e);
redisSetRequestErrors.mark();
return resultWithError;
return LookupResult.withError();
} finally {
time.stop();
}
@ -189,9 +187,8 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
try {
final Long result = this.commands.del(key.toString());
if (result != 1) {
LOG.warn("Redis DEL key <{}> returned {}", key, result);
LOG.debug("Redis DEL key <{}> returned {}", key, result);
redisSetRequestErrors.mark();
return resultWithError;
}
return;
} catch (Exception e) {
@ -203,7 +200,6 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
}
}
@Override
public LookupResult assignTtl(Object key, Long ttlSec) {
final Timer.Context time = redisSetRequestTimer.time();
final String trimmedKey = StringUtils.trimToNull(key.toString());
@ -212,14 +208,14 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
if (!result) {
LOG.warn("Redis EXPIRE key <{}> to <{}> returned {}", key, ttlSec, result);
redisSetRequestErrors.mark();
return resultWithError;
return LookupResult.withError();
}
final String value = this.commands.get(trimmedKey);
return LookupResult.single(value.toString());
} catch (Exception e) {
LOG.error("Redis EXPIRE key <{}> to <{}> returned {}", key, ttlSec, e);
redisSetRequestErrors.mark();
return resultWithError;
return LookupResult.withError();
} finally {
time.stop();
}