Add TTL to created keys
This commit is contained in:
parent
5359bb1217
commit
273de7caa1
@ -158,7 +158,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
public LookupResult setValue(Object key, Object value) {
|
public LookupResult setValue(Object key, Object value) {
|
||||||
final Timer.Context time = redisSetRequestTimer.time();
|
final Timer.Context time = redisSetRequestTimer.time();
|
||||||
try {
|
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")) {
|
if (!result.equals("OK")) {
|
||||||
LOG.warn("Redis SET key <{}> to value <{}> returned {}", key, value, result);
|
LOG.warn("Redis SET key <{}> to value <{}> returned {}", key, value, result);
|
||||||
redisSetRequestErrors.mark();
|
redisSetRequestErrors.mark();
|
||||||
@ -194,6 +194,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
.redisHost("127.0.0.1")
|
.redisHost("127.0.0.1")
|
||||||
.redisPort(6379)
|
.redisPort(6379)
|
||||||
.redisDB(0)
|
.redisDB(0)
|
||||||
|
.redisKeyTTL(86400)
|
||||||
.redisUsername("")
|
.redisUsername("")
|
||||||
.redisPassword("")
|
.redisPassword("")
|
||||||
.build();
|
.build();
|
||||||
@ -208,31 +209,35 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
@JsonTypeName(NAME)
|
@JsonTypeName(NAME)
|
||||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
public abstract static class Config implements LookupDataAdapterConfiguration {
|
public abstract static class Config implements LookupDataAdapterConfiguration {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@JsonProperty(TYPE_FIELD)
|
@JsonProperty(TYPE_FIELD)
|
||||||
public abstract String type();
|
public abstract String type();
|
||||||
|
|
||||||
@JsonProperty("redis_host")
|
@JsonProperty("redis_host")
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
public abstract String redisHost();
|
public abstract String redisHost();
|
||||||
|
|
||||||
@JsonProperty("redis_port")
|
@JsonProperty("redis_port")
|
||||||
@Min(1)
|
@Min(1)
|
||||||
public abstract int redisPort();
|
public abstract int redisPort();
|
||||||
|
|
||||||
@JsonProperty("redis_database")
|
@JsonProperty("redis_database")
|
||||||
@Min(0)
|
@Min(0)
|
||||||
public abstract int redisDB();
|
public abstract int redisDB();
|
||||||
|
|
||||||
|
@JsonProperty("redis_ttl")
|
||||||
|
@Min(0)
|
||||||
|
public abstract long redisKeyTTL();
|
||||||
|
|
||||||
@JsonProperty("redis_username")
|
@JsonProperty("redis_username")
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract String redisUsername();
|
public abstract String redisUsername();
|
||||||
|
|
||||||
@JsonProperty("redis_password")
|
@JsonProperty("redis_password")
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract String redisPassword();
|
public abstract String redisPassword();
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
return new AutoValue_RedisLookupDataAdapter_Config.Builder();
|
return new AutoValue_RedisLookupDataAdapter_Config.Builder();
|
||||||
}
|
}
|
||||||
@ -255,7 +260,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
public static Builder create() {
|
public static Builder create() {
|
||||||
return Config.builder();
|
return Config.builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty(TYPE_FIELD)
|
@JsonProperty(TYPE_FIELD)
|
||||||
public abstract Builder type(String type);
|
public abstract Builder type(String type);
|
||||||
|
|
||||||
@ -264,16 +269,19 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
|
|
||||||
@JsonProperty("redis_port")
|
@JsonProperty("redis_port")
|
||||||
public abstract Builder redisPort(int redisPort);
|
public abstract Builder redisPort(int redisPort);
|
||||||
|
|
||||||
@JsonProperty("redis_database")
|
@JsonProperty("redis_database")
|
||||||
public abstract Builder redisDB(int redisDB);
|
public abstract Builder redisDB(int redisDB);
|
||||||
|
|
||||||
|
@JsonProperty("redis_ttl")
|
||||||
|
public abstract Builder redisKeyTTL(long redisKeyTTL);
|
||||||
|
|
||||||
@JsonProperty("redis_username")
|
@JsonProperty("redis_username")
|
||||||
public abstract Builder redisUsername(String redisUsername);
|
public abstract Builder redisUsername(String redisUsername);
|
||||||
|
|
||||||
@JsonProperty("redis_password")
|
@JsonProperty("redis_password")
|
||||||
public abstract Builder redisPassword(String redisPassword);
|
public abstract Builder redisPassword(String redisPassword);
|
||||||
|
|
||||||
public abstract Config build();
|
public abstract Config build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@ class RedisLookupAdapterDocumentation extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p style={style}>
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -76,6 +76,17 @@ class RedisLookupAdapterFieldSet extends React.Component {
|
|||||||
value={config.redis_database}
|
value={config.redis_database}
|
||||||
labelClassName="col-sm-3"
|
labelClassName="col-sm-3"
|
||||||
wrapperClassName="col-sm-9" />
|
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"
|
<Input type="text"
|
||||||
id="redis_username"
|
id="redis_username"
|
||||||
name="redis_username"
|
name="redis_username"
|
||||||
|
Loading…
Reference in New Issue
Block a user