Send a command reconnecting the link if needed. */
| 1332 | |
| 1333 | /* Send a command reconnecting the link if needed. */ |
| 1334 | static redisReply *reconnectingRedisCommand(redisContext *c, const char *fmt, ...) { |
| 1335 | redisReply *reply = NULL; |
| 1336 | int tries = 0; |
| 1337 | va_list ap; |
| 1338 | |
| 1339 | assert(!c->err); |
| 1340 | while(reply == NULL) { |
| 1341 | while (c->err & (REDIS_ERR_IO | REDIS_ERR_EOF)) { |
| 1342 | printf("\r\x1b[0K"); /* Cursor to left edge + clear line. */ |
| 1343 | printf("Reconnecting... %d\r", ++tries); |
| 1344 | fflush(stdout); |
| 1345 | |
| 1346 | redisFree(c); |
| 1347 | c = redisConnect(config.hostip,config.hostport); |
| 1348 | if (!c->err && config.tls) { |
| 1349 | const char *err = NULL; |
| 1350 | if (cliSecureConnection(c, config.sslconfig, &err) == REDIS_ERR && err) { |
| 1351 | fprintf(stderr, "TLS Error: %s\n", err); |
| 1352 | exit(1); |
| 1353 | } |
| 1354 | } |
| 1355 | usleep(1000000); |
| 1356 | } |
| 1357 | |
| 1358 | va_start(ap,fmt); |
| 1359 | reply = redisvCommand(c,fmt,ap); |
| 1360 | va_end(ap); |
| 1361 | |
| 1362 | if (c->err && !(c->err & (REDIS_ERR_IO | REDIS_ERR_EOF))) { |
| 1363 | fprintf(stderr, "Error: %s\n", c->errstr); |
| 1364 | exit(1); |
| 1365 | } else if (tries > 0) { |
| 1366 | printf("\r\x1b[0K"); /* Cursor to left edge + clear line. */ |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | context = c; |
| 1371 | return reply; |
| 1372 | } |
| 1373 | |
| 1374 | /*------------------------------------------------------------------------------ |
| 1375 | * User interface |
no test coverage detected