diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfigReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfigReader.kt index bcc49786..38a40ab6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfigReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfigReader.kt @@ -35,19 +35,22 @@ class CacheConfigReader : YamlConfigReader(), ConfigReader { val config = CacheConfig() getMapping(node, "redis")?.let { node -> val redis = CacheConfig.Redis() - getValueAsString(node, "host")?.let { - redis.host = it + val enabled = getValueAsBool(node, "enabled") ?: true + if (enabled) { + getValueAsString(node, "host")?.let { + redis.host = it + } + getValueAsInt(node, "port")?.let { + redis.port = it + } + getValueAsInt(node, "db")?.let { + redis.db = it + } + getValueAsString(node, "password")?.let { + redis.password = it + } + config.redis = redis } - getValueAsInt(node, "port")?.let { - redis.port = it - } - getValueAsInt(node, "db")?.let { - redis.db = it - } - getValueAsString(node, "password")?.let { - redis.password = it - } - config.redis = redis } if (config.redis == null) { return null diff --git a/src/test/groovy/io/emeraldpay/dshackle/config/CacheConfigReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/config/CacheConfigReaderSpec.groovy index 2c20a3b6..8b0901ed 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/config/CacheConfigReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/config/CacheConfigReaderSpec.groovy @@ -36,4 +36,15 @@ class CacheConfigReaderSpec extends Specification { password == "HelloWorld!1" } } + + def "Read disabled"() { + setup: + def config = this.class.getClassLoader().getResourceAsStream("cache-redis-disabled.yaml") + when: + def act = reader.read(config) + + then: + //later may be not null if we support something else besides Redis + act == null + } } diff --git a/src/test/resources/cache-redis-disabled.yaml b/src/test/resources/cache-redis-disabled.yaml new file mode 100644 index 00000000..939cbcb9 --- /dev/null +++ b/src/test/resources/cache-redis-disabled.yaml @@ -0,0 +1,7 @@ +cache: + redis: + enabled: false + host: redis-master + port: 1234 + db: 5 + password: HelloWorld!1 \ No newline at end of file