我正在尝试运行hiredis
。C
CentOS
以下代码似乎运行良好:
...
const char *hostname = "my.redis-as-a-service.com";
int port = 8765;
const char *cert = "-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----\n";
const char *key = "-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----\n";
const char *ca = "-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----\n";
struct timeval tv = { 1, 500000 }; // 1.5 seconds
redisOptions options = {0};
REDIS_OPTIONS_SET_TCP(&options, hostname, port);
options.timeout = &tv;
c = redisConnectWithOptions(&options);
if (c == NULL || c->err) {
if (c) {
printf("Connection error: %s\n", c->errstr);
redisFree(c);
} else {
printf("Connection error: can't allocate redis context\n");
}
exit(1);
}
if (redisSecureConnection(c, ca, cert, key, "sni") != REDIS_OK) {
printf("Couldn't initialize SSL!\n");
printf("Error: %s\n", c->errstr);
redisFree(c);
exit(1);
}
但是,当我尝试在 url 中针对 which require 运行它时,例如Compose.com
:username
password
const char *hostname = "USERNAME:PASSWORD@my.redis-as-a-service.com";
然后它会失败而没有特定错误。简单的:
Connection error: Name or service not known