Fix RedisUtils.isUnlinkAvailable() for NPE

Fixes https://github.com/spring-projects/spring-integration/issues/2868

* Check if `redis_version` property is returned from the `info`
before parsing

**Cherry-pick to 5.1.x**
This commit is contained in:
Artem Bilan
2019-03-29 12:10:37 -04:00
committed by Gary Russell
parent 6f3fd0961f
commit 659613c4c9

View File

@@ -23,6 +23,7 @@ import java.util.Properties;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.util.StringUtils;
/**
* A set of utility methods for common Redis functions.
@@ -61,8 +62,14 @@ public final class RedisUtils {
Properties info = redisOperations.execute(
(RedisCallback<Properties>) connection -> connection.serverCommands().info(SECTION));
if (info != null) {
int majorVersion = Integer.parseInt(info.getProperty(VERSION_PROPERTY).split("\\.")[0]);
return majorVersion >= 4;
String version = info.getProperty(VERSION_PROPERTY);
if (StringUtils.hasText(version)) {
int majorVersion = Integer.parseInt(version.split("\\.")[0]);
return majorVersion >= 4;
}
else {
return false;
}
}
else {
throw new IllegalStateException("The INFO command cannot be used in pipeline/transaction.");