{"record":{"id":"4b1002a82264e9c2","repo":"phalcon/cphalcon","slug":"could-not-connect-to-the-redis-server-s-s","errorCode":null,"errorMessage":"Could not connect to the Redis server [%s:%s]","messagePattern":"Could not connect to the Redis server \\[(.+?):(.+?)\\]","errorType":"exception","errorClass":"Phalcon\\Storage\\Exceptions\\ConnectionFailed","httpStatus":null,"severity":"error","filePath":"phalcon/Storage/Adapter/Redis.zep","lineNumber":448,"sourceCode":"        }\n\n        /** @var storage_redis_context $connectionOptions */\n        try {\n            let result = connection->{method}(\n                host,\n                port,\n                timeout,\n                parameter,\n                retryInterval,\n                readTimeout,\n                connectionOptions\n            );\n        } catch \\Exception, ex {\n            throw new ConnectionFailed(ex->getMessage());\n        }\n\n        if !result {\n            throw new ConnectionFailed(\n                sprintf(\n                    \"Could not connect to the Redis server [%s:%s]\",\n                    host,\n                    port\n                )\n            );\n        }\n\n        return this;\n    }\n\n    /**\n     * @throws DatabaseSelectionFailed\n     */\n    private function checkIndex(<RedisService> connection) -> <static>\n    {\n        var index;\n","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Storage/Adapter/Redis.zep#L430-L466","documentation":"The companion of the exception path: when phpredis connect()/pconnect() signals failure by returning false instead of throwing, Phalcon formats the configured host and port into ConnectionFailed('Could not connect to the Redis server [host:port]'). Same network causes, different phpredis failure mode.","triggerScenarios":"Server down or port closed on phpredis builds that return false rather than raising RedisException; TLS timeouts during handshake; pconnect() with a stale 'persistentId' socket after a Redis restart, where reconnect fails silently.","commonSituations":"Upgrading or downgrading ext-redis changes whether failures throw or return false, so the same outage surfaces with a different message; long-lived queue workers using persistent connections across Redis restarts.","solutions":["Read the host:port from the message and diff it against the running server config (defaults are 127.0.0.1:6379)","Confirm from the app container: redis-cli -h <host> -p <port> PING","For persistent connections, change or drop 'persistentId' to force a fresh socket, or set 'retryInterval' so phpredis retries","Handle both ConnectionFailed messages identically in your cache wrapper"],"exampleFix":"// before: stale persistent socket after redis restart\nnew Redis($factory, ['persistent' => true, 'persistentId' => 'worker-1']);\n\n// after: allow reconnect\nnew Redis($factory, ['persistent' => true, 'persistentId' => 'worker-1', 'retryInterval' => 100]);","handlingStrategy":"retry","validationCode":"// normalize config so both failure modes point at the right target\n$options['host'] = (string) ($options['host'] ?? '127.0.0.1');\n$options['port'] = (int) ($options['port'] ?? 6379);\nif ($options['persistent'] ?? false) {\n    $options['retryInterval'] = (int) ($options['retryInterval'] ?? 100);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return $cache->get($key);\n} catch (\\Phalcon\\Storage\\Exceptions\\ConnectionFailed $e) {\n    // message contains 'Could not connect to the Redis server [host:port]' — verify that target\n    if (str_contains($e->getMessage(), 'Could not connect to the Redis server')) {\n        return $default; // false-return mode of phpredis; same handling as 711\n    }\n    throw $e;\n}","preventionTips":["Pin ext-redis versions across environments so the throw-vs-false-return mode is consistent","For persistent connections set retryInterval and recycle persistentId after long downtime windows","Log the host:port from the message and diff against config when triaging"],"tags":["php","phalcon","redis","cache","network","connection"],"backgroundTag":"connection-refused","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}