MCPcopy Create free account
hub / github.com/apache/brpc / PickEndpointForKey

Method PickEndpointForKey

src/brpc/redis_cluster.cpp:608–629  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

606}
607
608bool RedisClusterChannel::PickEndpointForKey(const std::string& key,
609 std::string* endpoint,
610 int* slot) const {
611 const int key_slot = HashSlot(key);
612 if (key_slot < 0 || key_slot >= static_cast<int>(kRedisClusterSlotCount)) {
613 return false;
614 }
615 butil::DoublyBufferedData<std::vector<std::string> >::ScopedPtr s;
616 if (_db_slot_to_endpoint.Read(&s) != 0 ||
617 static_cast<size_t>(key_slot) >= s->size()) {
618 return false;
619 }
620 const std::string& mapped = (*s)[key_slot];
621 if (mapped.empty()) {
622 return false;
623 }
624 *endpoint = mapped;
625 if (slot != NULL) {
626 *slot = key_slot;
627 }
628 return true;
629}
630
631bool RedisClusterChannel::PickAnyEndpoint(std::string* endpoint) const {
632 BAIDU_SCOPED_LOCK(_mutex);

Callers

nothing calls this directly

Calls 4

HashSlotFunction · 0.85
ReadMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected