Add TTL to created keys

This commit is contained in:
yo000 2024-02-03 19:49:06 +01:00
parent 5359bb1217
commit 273de7caa1
3 changed files with 35 additions and 14 deletions

View File

@ -158,7 +158,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
public LookupResult setValue(Object key, Object value) {
final Timer.Context time = redisSetRequestTimer.time();
try {
final String result = this.commands.set(key.toString(), value.toString());
final String result = this.commands.setex(key.toString(), this.config.redisKeyTTL(), value.toString());
if (!result.equals("OK")) {
LOG.warn("Redis SET key <{}> to value <{}> returned {}", key, value, result);
redisSetRequestErrors.mark();
@ -194,6 +194,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
.redisHost("127.0.0.1")
.redisPort(6379)
.redisDB(0)
.redisKeyTTL(86400)
.redisUsername("")
.redisPassword("")
.build();
@ -225,6 +226,10 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
@Min(0)
public abstract int redisDB();
@JsonProperty("redis_ttl")
@Min(0)
public abstract long redisKeyTTL();
@JsonProperty("redis_username")
@Nullable
public abstract String redisUsername();
@ -268,6 +273,9 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
@JsonProperty("redis_database")
public abstract Builder redisDB(int redisDB);
@JsonProperty("redis_ttl")
public abstract Builder redisKeyTTL(long redisKeyTTL);
@JsonProperty("redis_username")
public abstract Builder redisUsername(String redisUsername);

View File

@ -23,7 +23,9 @@ class RedisLookupAdapterDocumentation extends React.Component {
return (
<div>
<p style={style}>
The Redis Lookup data adapter lookup redis for the given key and returns the values .
The Redis Lookup data adapter lookup redis for the given key and returns the values.<br/>
It supports writing key/values to Redis (SET command). <br/>
All created keys will have the TTL configured for the data adapter.
</p>
</div>
)

View File

@ -76,6 +76,17 @@ class RedisLookupAdapterFieldSet extends React.Component {
value={config.redis_database}
labelClassName="col-sm-3"
wrapperClassName="col-sm-9" />
<Input type="text"
id="redis_ttl"
name="redis_ttl"
label="Redis key TTL"
required
onChange={this.props.handleFormEvent}
help={this.props.validationMessage('redis_ttl', 'Redis key TTL in seconds')}
bsStyle={this.props.validationState('redis_ttl')}
value={config.redis_ttl}
labelClassName="col-sm-3"
wrapperClassName="col-sm-9" />
<Input type="text"
id="redis_username"
name="redis_username"