diff --git a/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java b/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java index 295cfc8..8a45928 100755 --- a/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java +++ b/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java @@ -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(); @@ -208,31 +209,35 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { @JsonTypeName(NAME) @JsonInclude(JsonInclude.Include.NON_EMPTY) public abstract static class Config implements LookupDataAdapterConfiguration { - - @Override + + @Override @JsonProperty(TYPE_FIELD) public abstract String type(); - + @JsonProperty("redis_host") @NotEmpty public abstract String redisHost(); - + @JsonProperty("redis_port") @Min(1) public abstract int redisPort(); - + @JsonProperty("redis_database") @Min(0) public abstract int redisDB(); - + + @JsonProperty("redis_ttl") + @Min(0) + public abstract long redisKeyTTL(); + @JsonProperty("redis_username") @Nullable public abstract String redisUsername(); - + @JsonProperty("redis_password") @Nullable public abstract String redisPassword(); - + public static Builder builder() { return new AutoValue_RedisLookupDataAdapter_Config.Builder(); } @@ -255,7 +260,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { public static Builder create() { return Config.builder(); } - + @JsonProperty(TYPE_FIELD) public abstract Builder type(String type); @@ -264,16 +269,19 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { @JsonProperty("redis_port") public abstract Builder redisPort(int redisPort); - + @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); - + @JsonProperty("redis_password") public abstract Builder redisPassword(String redisPassword); - + public abstract Config build(); } } diff --git a/src/web/dataadapters/RedisLookupAdapterDocumentation.jsx b/src/web/dataadapters/RedisLookupAdapterDocumentation.jsx index 98ef726..9559e57 100644 --- a/src/web/dataadapters/RedisLookupAdapterDocumentation.jsx +++ b/src/web/dataadapters/RedisLookupAdapterDocumentation.jsx @@ -23,7 +23,9 @@ class RedisLookupAdapterDocumentation extends React.Component { return (

- 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.
+ It supports writing key/values to Redis (SET command).
+ All created keys will have the TTL configured for the data adapter.

) diff --git a/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx b/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx index 67b93f5..e198fea 100644 --- a/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx +++ b/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx @@ -76,6 +76,17 @@ class RedisLookupAdapterFieldSet extends React.Component { value={config.redis_database} labelClassName="col-sm-3" wrapperClassName="col-sm-9" /> +