Send a command reconnecting the link if needed. */
| 1525 | |
| 1526 | /* Send a command reconnecting the link if needed. */ |
| 1527 | static redisReply *reconnectingRedisCommand(redisContext *c, const char *fmt, ...) { |
| 1528 | redisReply *reply = NULL; |
| 1529 | int tries = 0; |
| 1530 | va_list ap; |
| 1531 | |
| 1532 | assert(!c->err); |
| 1533 | while(reply == NULL) { |
| 1534 | while (c->err & (REDIS_ERR_IO | REDIS_ERR_EOF)) { |
| 1535 | printf("\r\x1b[0K"); /* Cursor to left edge + clear line. */ |
| 1536 | printf("Reconnecting... %d\r", ++tries); |
| 1537 | fflush(stdout); |
| 1538 | |
| 1539 | redisFree(c); |
| 1540 | c = redisConnect(config.hostip,config.hostport); |
| 1541 | if (!c->err && config.tls) { |
| 1542 | const char *err = NULL; |
| 1543 | if (cliSecureConnection(c, config.sslconfig, &err) == REDIS_ERR && err) { |
| 1544 | fprintf(stderr, "TLS Error: %s\n", err); |
| 1545 | exit(1); |
| 1546 | } |
| 1547 | } |
| 1548 | usleep(1000000); |
| 1549 | } |
| 1550 | |
| 1551 | va_start(ap,fmt); |
| 1552 | reply = redisvCommand(c,fmt,ap); |
| 1553 | va_end(ap); |
| 1554 | |
| 1555 | if (c->err && !(c->err & (REDIS_ERR_IO | REDIS_ERR_EOF))) { |
| 1556 | fprintf(stderr, "Error: %s\n", c->errstr); |
| 1557 | exit(1); |
| 1558 | } else if (tries > 0) { |
| 1559 | printf("\r\x1b[0K"); /* Cursor to left edge + clear line. */ |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | context = c; |
| 1564 | return reply; |
| 1565 | } |
| 1566 | |
| 1567 | /*------------------------------------------------------------------------------ |
| 1568 | * User interface |
no test coverage detected