{"record":{"id":"c370287fd3a247db","repo":"alibaba/Sentinel","slug":"cannot-build-a-redisconnectionconfig-one-of-the-f","errorCode":null,"errorMessage":"Cannot build a RedisConnectionConfig. One of the following must be provided Host, Socket, Cluster or Sentinel","messagePattern":"Cannot build a RedisConnectionConfig\\. One of the following must be provided Host, Socket, Cluster or Sentinel","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sentinel-extension/sentinel-datasource-redis/src/main/java/com/alibaba/csp/sentinel/datasource/redis/config/RedisConnectionConfig.java","lineNumber":710,"sourceCode":"\n        /**\n         * Sets the keyFilePassword.\n         *\n         * @param keyFilePassword keyFilePassword\n         * @return the value of Builder\n         */\n        public RedisConnectionConfig.Builder withKeyFilePassword(String keyFilePassword) {\n            this.keyFilePassword = keyFilePassword;\n            return this;\n        }\n\n        /**\n         * @return the RedisConnectionConfig.\n         */\n        public RedisConnectionConfig build() {\n\n            if (redisSentinels.isEmpty() && redisClusters.isEmpty() && StringUtil.isEmpty(host)) {\n                throw new IllegalStateException(\n                    \"Cannot build a RedisConnectionConfig. One of the following must be provided Host, Socket, Cluster or \"\n                        + \"Sentinel\");\n            }\n\n            RedisConnectionConfig redisConnectionConfig = new RedisConnectionConfig();\n            redisConnectionConfig.setHost(host);\n            redisConnectionConfig.setPort(port);\n\n            if (sslEnable){\n                redisConnectionConfig.setSslEnable(true);\n                redisConnectionConfig.setTrustedCertificatesPath(trustedCertificatesPath);\n                redisConnectionConfig.setTrustedCertificatesJksPassword(trustedCertificatesJksPassword);\n                redisConnectionConfig.setKeyCertChainFilePath(keyCertChainFilePath);\n                redisConnectionConfig.setKeyFilePath(keyFilePath);\n                redisConnectionConfig.setKeyFilePassword(keyFilePassword);\n            }\n\n            if (password != null) {","sourceCodeStart":692,"sourceCodeEnd":728,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-extension/sentinel-datasource-redis/src/main/java/com/alibaba/csp/sentinel/datasource/redis/config/RedisConnectionConfig.java#L692-L728","documentation":"Thrown by RedisConnectionConfig.Builder.build() when no connection target was configured: the builder has no host, no cluster nodes, and no sentinel nodes. Sentinel's builder (modeled on Spring Data Redis) requires at least one of standalone host, unix socket, cluster, or sentinel addresses before it can produce a config.","triggerScenarios":"Calling build() after only setting port, password, database, or SSL options — e.g. RedisConnectionConfig.builder().withPort(6379).withPassword(...).build() with no withHost/withSentinel/withCluster/withUnixSocket call.","commonSituations":"Config properties for the Redis host are optional and unset in one environment; refactoring renames the host property so withHost receives null/empty and the builder silently keeps an empty host; copy-paste builder chains that drop the host line.","solutions":["Add a target: withHost(\"127.0.0.1\") (optionally withPort) for standalone, or withCluster(\"host:port\", ...), or withSentinel(\"host:port\") for sentinel.","Validate your config source before building: assert the host/nodes property is non-empty and fail with its name.","Build the config once in a factory method with integration-test coverage so a missing host fails CI, not production."],"exampleFix":"// before\nRedisConnectionConfig cfg = RedisConnectionConfig.builder()\n    .withPort(6379).withPassword(\"secret\").build(); // no host -> throws\n\n// after\nRedisConnectionConfig cfg = RedisConnectionConfig.builder()\n    .withHost(\"127.0.0.1\").withPort(6379).withPassword(\"secret\").build();","handlingStrategy":"validation","validationCode":"RedisConnectionConfig.Builder b = RedisConnectionConfig.builder();\nif (host != null && !host.isEmpty()) { b.withHost(host).withPort(port); }\nelse if (nodes != null && !nodes.isEmpty()) { for (String n : nodes) b.withCluster(n); }\nelse { throw new IllegalStateException(\"redis host or cluster/sentinel nodes must be configured\"); }\nRedisConnectionConfig cfg = b.build();","typeGuard":null,"tryCatchPattern":"try {\n    cfg = builder.build();\n} catch (IllegalStateException e) {\n    throw new IllegalStateException(\"RedisConnectionConfig incomplete: set host, unix socket, cluster or sentinel nodes\", e);\n}","preventionTips":["Make the Redis host/nodes property required in your config schema.","Add an integration test that builds the config from production-like properties."],"tags":["sentinel","redis","builder","connection-config","constructor-validation","java"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}