MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / clusterManagerNodeConnect

Function clusterManagerNodeConnect

src/redis-cli.c:2525–2565  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2523}
2524
2525static int clusterManagerNodeConnect(clusterManagerNode *node) {
2526 if (node->context) redisFree(node->context);
2527 struct timeval tv;
2528 tv.tv_sec = config.cluster_manager_command.timeout / 1000;
2529 tv.tv_usec = (config.cluster_manager_command.timeout % 1000) * 1000;
2530 node->context = redisConnectWithTimeout(node->ip, node->port, tv);
2531 if (!node->context->err && config.tls) {
2532 const char *err = NULL;
2533 if (cliSecureConnection(node->context, config.sslconfig, &err) == REDIS_ERR && err) {
2534 fprintf(stderr,"TLS Error: %s\n", err);
2535 redisFree(node->context);
2536 node->context = NULL;
2537 return 0;
2538 }
2539 }
2540 if (node->context->err) {
2541 fprintf(stderr,"Could not connect to KeyDB at ");
2542 fprintf(stderr,"%s:%d: %s\n", node->ip, node->port,
2543 node->context->errstr);
2544 redisFree(node->context);
2545 node->context = NULL;
2546 return 0;
2547 }
2548 /* Set aggressive KEEP_ALIVE socket option in the Redis context socket
2549 * in order to prevent timeouts caused by the execution of long
2550 * commands. At the same time this improves the detection of real
2551 * errors. */
2552 anetKeepAlive(NULL, node->context->fd, REDIS_CLI_KEEPALIVE_INTERVAL);
2553 if (config.auth) {
2554 redisReply *reply;
2555 if (config.user == NULL)
2556 reply = redisCommand(node->context,"AUTH %s", config.auth);
2557 else
2558 reply = redisCommand(node->context,"AUTH %s %s",
2559 config.user,config.auth);
2560 int ok = clusterManagerCheckRedisReply(node, reply, NULL);
2561 if (reply != NULL) freeReplyObject(reply);
2562 if (!ok) return 0;
2563 }
2564 return 1;
2565}
2566
2567static void clusterManagerRemoveNodeFromList(list *nodelist,
2568 clusterManagerNode *node) {

Calls 7

redisFreeFunction · 0.85
redisConnectWithTimeoutFunction · 0.85
cliSecureConnectionFunction · 0.85
anetKeepAliveFunction · 0.85
freeReplyObjectFunction · 0.85
redisCommandClass · 0.70

Tested by

no test coverage detected