Exemplo n.º 1
0
Variant c_Memcached::t_getmultibykey(CStrRef server_key, CArrRef keys,
                                     VRefParam cas_tokens /*= null_variant*/,
                                     int flags /*= 0*/) {
  INSTANCE_METHOD_INJECTION_BUILTIN(Memcached, Memcached::getmultibykey);
  m_impl->rescode = q_Memcached_RES_SUCCESS;

  bool preserveOrder = flags & q_Memcached_GET_PRESERVE_ORDER;
  Array returnValue;
  if (!getMultiImpl(server_key, keys, cas_tokens.isReferenced(),
                    preserveOrder ? &returnValue : NULL)) {
    return false;
  }

  if (cas_tokens.isReferenced()) cas_tokens = Array();
  MemcachedResultWrapper result(&m_impl->memcached);
  memcached_return status;
  while (memcached_fetch_result(&m_impl->memcached, &result.value, &status)) {
    Variant value;
    if (!toObject(value, result.value)) {
      m_impl->rescode = q_Memcached_RES_PAYLOAD_FAILURE;
      return false;
    }
    const char *key  = memcached_result_key_value(&result.value);
    size_t keyLength = memcached_result_key_length(&result.value);
    String sKey(key, keyLength, CopyString);
    returnValue.set(sKey, value, true);
    if (cas_tokens.isReferenced()) {
      double cas = (double) memcached_result_cas(&result.value);
      cas_tokens->set(sKey, cas, true);
    }
  }

  if (status != MEMCACHED_END && !handleError(status)) return false;
  return returnValue;
}