Beispiel #1
0
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;
}
Beispiel #2
0
bool CacheManagerI::deleteListCache(const std::string& key, 
                                    const std::string& namespace_id, 
                                    const std::string& business_id, 
                                    const Ice::Current& current) {
  std::ostringstream otem;
  otem << "CacheManageI::deleteListCache() key:" << key
       << "\tnamespace_id:" << namespace_id 
       << "\tbusiness_id:" << business_id;
  MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, otem.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO);
  RedisCacheClientPtr cache = GetRedisCache();
  if (cache == NULL) {
    MCE_WARN("GetRedisCache() return NULL");
    return false;
  }
  return cache->Remove(key, namespace_id, business_id);
}
Beispiel #3
0
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);
          }
        }
      }