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