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

Function reconnectingRedisCommand

src/redis-cli.c:1334–1372  ·  view source on GitHub ↗

Send a command reconnecting the link if needed. */

Source from the content-addressed store, hash-verified

1332
1333/* Send a command reconnecting the link if needed. */
1334static 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

Callers 4

latencyModeFunction · 0.85
latencyDistModeFunction · 0.85
statModeFunction · 0.85

Calls 4

redisFreeFunction · 0.85
redisConnectFunction · 0.85
cliSecureConnectionFunction · 0.85
redisvCommandFunction · 0.85

Tested by

no test coverage detected