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

Function getSentinelRedisInstanceByAddrAndRunID

src/sentinel.cpp:1488–1518  ·  view source on GitHub ↗

Search an instance with the same runid, ip and port into a dictionary * of instances. Return NULL if not found, otherwise return the instance * pointer. * * runid or addr can be NULL. In such a case the search is performed only * by the non-NULL field. */

Source from the content-addressed store, hash-verified

1486 * runid or addr can be NULL. In such a case the search is performed only
1487 * by the non-NULL field. */
1488sentinelRedisInstance *getSentinelRedisInstanceByAddrAndRunID(dict *instances, char *addr, int port, char *runid) {
1489 dictIterator *di;
1490 dictEntry *de;
1491 sentinelRedisInstance *instance = NULL;
1492 sentinelAddr *ri_addr = NULL;
1493
1494 serverAssert(addr || runid); /* User must pass at least one search param. */
1495 if (addr != NULL) {
1496 /* Resolve addr, we use the IP as a key even if a hostname is used */
1497 ri_addr = createSentinelAddr(addr, port);
1498 if (!ri_addr) return NULL;
1499 }
1500 di = dictGetIterator(instances);
1501 while((de = dictNext(di)) != NULL) {
1502 sentinelRedisInstance *ri = (sentinelRedisInstance*)dictGetVal(de);
1503
1504 if (runid && !ri->runid) continue;
1505 if ((runid == NULL || strcmp(ri->runid, runid) == 0) &&
1506 (addr == NULL || (strcmp(ri->addr->ip, ri_addr->ip) == 0 &&
1507 ri->addr->port == port)))
1508 {
1509 instance = ri;
1510 break;
1511 }
1512 }
1513 dictReleaseIterator(di);
1514 if (ri_addr != NULL)
1515 releaseSentinelAddr(ri_addr);
1516
1517 return instance;
1518}
1519
1520/* Master lookup by name */
1521sentinelRedisInstance *sentinelGetMasterByName(char *name) {

Calls 5

createSentinelAddrFunction · 0.85
releaseSentinelAddrFunction · 0.85
dictGetIteratorFunction · 0.70
dictNextFunction · 0.70
dictReleaseIteratorFunction · 0.70

Tested by

no test coverage detected