bool CacheManagerI::loadListCache(const std::string& key, const std::string& namespace_id, const std::string& business_id, bool use_master, const Ice::Current& current) { std::ostringstream otem; otem << "CacheManageI::loadListCache() key:" << key << "\tnamespace_id:" << namespace_id << "\tbusiness_id:" << business_id; MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, otem.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO); ProducerManagerClientPtr producer = getProducer(); if(producer == NULL) { return false; } KeySeq keys; keys.push_back(key); DataMap data = producer->produce(keys, business_id, use_master, 0); if (data.empty()) { return true; } std::string list_key; StrList list_value; DataMap::const_iterator iter = data.begin(); list_key = iter->second; for (; iter != data.end(); ++iter) { list_value.push_back(iter->first); } RedisCacheClientPtr redis_client = GetRedisCache(); redis_client->Set(list_key, list_value, namespace_id, business_id); return true; }
bool CacheManagerI::load(const KeySeq& keys, const std::string& namespaceId, const std::string& businessId, long expiredTime, bool useMaster, const Ice::Current& current) { std::ostringstream os; os<<"Key : "; for(KeySeq::const_iterator it = keys.begin(); it != keys.end(); ++it) { os<<*it<<" "; } os<<" namespaceId :"<<namespaceId; os<<" businessId :"<<businessId; os<<" expiredTime :"<<expiredTime; os<<" useMaster :"<<useMaster; MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, os.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO); ProducerManagerClientPtr producer = getProducer(); if(producer == NULL) { return false; } bool sucFlag = true; KeySeq inputKeys(keys.begin(), keys.end()); KeySeq lockedKeys; KeySeq failedLockedKeys; DataMap res; while(true) { xce::tempmutext::Locks<std::string> locks(&tempMutexManager_, inputKeys, lockedKeys, failedLockedKeys); if(!lockedKeys.empty()) { DataMap singleRes = producer->produce(keys, businessId, useMaster, 1000); if(!singleRes.empty()) { res.insert(singleRes.begin(), singleRes.end()); } CacheClientPtr cache = getCache(); if(cache != NULL) { for(DataMap::const_iterator it = singleRes.begin(); it != singleRes.end(); ++it) { sucFlag &= cache->set(it->first, it->second, namespaceId, businessId, expiredTime, 1000); } } if(failedLockedKeys.empty()) { break; } } inputKeys.swap(failedLockedKeys); lockedKeys.clear(); failedLockedKeys.clear(); } return sucFlag; }
bool CacheManagerI::loadListCache(const std::string& key, const std::string& namespace_id, const std::string& biz_id, bool use_master, const Ice::Current& current) { std::ostringstream os; os << "key :" << key; os << " namespaceId :" << namespace_id; os << " businessId :" << biz_id; os << " use_master :" << use_master; MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, os.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO); ProducerManagerClientPtr producer = getProducer(); if(!producer) { MCE_ERROR("CacheManagerI::loadListCache() getProducer() return NULL!!!"); return false; } KeySeq input_keys; input_keys.push_back(key); KeySeq locked_keys; KeySeq failed_locked_keys; bool result = false; while(true) { xce::tempmutext::Locks<std::string> locks(&tempMutexManager_, input_keys, locked_keys, failed_locked_keys); if(!locked_keys.empty()) { DataMap data; try { data = producer->produce(locked_keys, biz_id, use_master, 10000); } catch (Ice::Exception& e) { MCE_ERROR("CacheManagerI::loadListCache() rpc call produce() " << e.what()); } DataMap::const_iterator iter = data.begin(); for (; iter != data.end(); ++iter) { if (!iter->second.empty()) { ListOrHashValue list_value; list_value.ParseFromArray(iter->second.data(), iter->second.size()); if (list_value.values_size() > 0) { StrList str_list; BOOST_FOREACH(const std::string& v, list_value.values()) { str_list.push_back(v); } RedisCacheClientPtr cache = GetRedisCache(); if (!cache) { MCE_ERROR("CacheManagerI::loadListCache() GetRedisCache() return NULL !!!"); continue; } result = cache->SetList(key, str_list, namespace_id, biz_id); } } }