MCPcopy Create free account
hub / github.com/F-Stack/f-stack / getSentinelRedisInstanceByAddrAndRunID

Function getSentinelRedisInstanceByAddrAndRunID

app/redis-6.2.6/src/sentinel.c:1482–1512  ·  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

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

Calls 6

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

Tested by

no test coverage detected