Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
e1f6e0ad60 | |||
e77d4d915d | |||
0a0748172e | |||
8febd14eb6 |
@ -10,7 +10,7 @@
|
||||
<groupId>in.nosd.redis</groupId>
|
||||
<artifactId>graylog-plugin-redis-lookup</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
<description>Graylog ${project.artifactId} plugin.</description>
|
||||
<url>https://www.graylog.org</url>
|
||||
<developers>
|
||||
|
2
pom.xml
2
pom.xml
@ -31,7 +31,7 @@
|
||||
|
||||
<groupId>in.nosd.redis</groupId>
|
||||
<artifactId>graylog-plugin-redis-lookup</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
|
@ -164,15 +164,20 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
||||
final Timer.Context time = redisSetRequestTimer.time();
|
||||
final String trimmedKey = StringUtils.trimToNull(key.toString());
|
||||
try {
|
||||
final String result = this.commands.setex(trimmedKey, ttlSec, value.toString());
|
||||
final String result;
|
||||
if (ttlSec > 0 ) {
|
||||
result = this.commands.setex(trimmedKey, ttlSec, value.toString());
|
||||
} else {
|
||||
result = this.commands.set(trimmedKey, value.toString());
|
||||
}
|
||||
if (!result.equals("OK")) {
|
||||
LOG.warn("Redis SETEX key <{}> to value <{}> with TTL <{}> returned {}", key, value, ttlSec, result);
|
||||
LOG.warn("Redis SET(EX) key <{}> to value <{}> with TTL <{}> returned {}", key, value, ttlSec, result);
|
||||
redisSetRequestErrors.mark();
|
||||
return LookupResult.empty();
|
||||
}
|
||||
return LookupResult.single(value.toString());
|
||||
} catch (Exception e) {
|
||||
LOG.error("Redis SETEX key <{}> to value <{}> with TTL <{}> returned an exception: {}", key, value, ttlSec, e);
|
||||
LOG.error("Redis SET(EX) key <{}> to value <{}> with TTL <{}> returned an exception: {}", key, value, ttlSec, e);
|
||||
redisSetRequestErrors.mark();
|
||||
return LookupResult.withError();
|
||||
} finally {
|
||||
@ -200,20 +205,48 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
private LookupResult setExpire(String key, Long ttl) {
|
||||
try {
|
||||
final Boolean result = this.commands.expire(key, ttl);
|
||||
if (!result) {
|
||||
LOG.warn("Redis EXPIRE key <{}> to <{}> returned {}", key, ttl, result);
|
||||
return LookupResult.withError();
|
||||
}
|
||||
final String value = this.commands.get(key);
|
||||
return LookupResult.single(value.toString());
|
||||
} catch (Exception e) {
|
||||
LOG.error("Redis EXPIRE key <{}> to <{}> returned {}", key, ttl, e);
|
||||
return LookupResult.withError(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private LookupResult setPersist(String key) {
|
||||
try {
|
||||
final Boolean result = this.commands.persist(key);
|
||||
if (!result) {
|
||||
LOG.warn("Redis PERSIST key <{}> returned {}", key, result);
|
||||
return LookupResult.withError();
|
||||
}
|
||||
final String value = this.commands.get(key);
|
||||
return LookupResult.single(value.toString());
|
||||
} catch (Exception e) {
|
||||
LOG.error("Redis PERSIST key <{}> returned {}", key, e);
|
||||
return LookupResult.withError(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// TTL -1 = never expire
|
||||
public LookupResult assignTtl(Object key, Long ttlSec) {
|
||||
final Timer.Context time = redisSetRequestTimer.time();
|
||||
final String trimmedKey = StringUtils.trimToNull(key.toString());
|
||||
try {
|
||||
final Boolean result = this.commands.expire(trimmedKey, ttlSec);
|
||||
if (!result) {
|
||||
LOG.warn("Redis EXPIRE key <{}> to <{}> returned {}", key, ttlSec, result);
|
||||
redisSetRequestErrors.mark();
|
||||
return LookupResult.withError();
|
||||
if (ttlSec > 0) {
|
||||
return setExpire(trimmedKey, ttlSec);
|
||||
} else {
|
||||
return setPersist(trimmedKey);
|
||||
}
|
||||
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);
|
||||
LOG.error("assignTtl <{}> to key <{}> returned {}", ttlSec, trimmedKey, e);
|
||||
redisSetRequestErrors.mark();
|
||||
return LookupResult.withError();
|
||||
} finally {
|
||||
@ -221,6 +254,11 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LookupResult setStringList(Object key, List<String> listValue) {
|
||||
return LookupResult.empty();
|
||||
}
|
||||
|
||||
public interface Factory extends LookupDataAdapter.Factory2<RedisLookupDataAdapter> {
|
||||
@Override
|
||||
RedisLookupDataAdapter create(@Assisted("dto") DataAdapterDto dto);
|
||||
@ -241,7 +279,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
||||
.redisHost("127.0.0.1")
|
||||
.redisPort(6379)
|
||||
.redisDB(0)
|
||||
.redisKeyTTL(86400)
|
||||
.redisKeyTTL(-1)
|
||||
.redisUsername("")
|
||||
.redisPassword("")
|
||||
.build();
|
||||
|
@ -76,7 +76,7 @@ public class RedisLookupPluginFunction extends LookupTableFunction<GenericLookup
|
||||
public FunctionDescriptor<GenericLookupResult> descriptor() {
|
||||
return FunctionDescriptor.<GenericLookupResult>builder()
|
||||
.name(NAME)
|
||||
.description("Match a key into Redis instance and return value")
|
||||
.description("Match a key into Redis instance and return value. Do not use, prefer standard 'lookup_*' functions")
|
||||
.params(keyParam)
|
||||
.returnType(GenericLookupResult.class)
|
||||
.build();
|
||||
|
@ -82,7 +82,7 @@ class RedisLookupAdapterFieldSet extends React.Component {
|
||||
label="Redis key TTL"
|
||||
required
|
||||
onChange={this.props.handleFormEvent}
|
||||
help={this.props.validationMessage('redis_ttl', 'Redis key TTL in seconds')}
|
||||
help={this.props.validationMessage('redis_ttl', 'Redis key TTL in seconds. Set -1 to not expire keys')}
|
||||
bsStyle={this.props.validationState('redis_ttl')}
|
||||
value={config.redis_ttl}
|
||||
labelClassName="col-sm-3"
|
||||
|
Reference in New Issue
Block a user