ESPCacheResult ESPMemCached::set(const char* groupID, const char* cacheID, const char* value, unsigned __int64 expireSec)
{
    memcached_return_t rc;
    size_t groupIDLength = strlen(groupID);
    if (groupIDLength)
        rc = memcached_set_by_key(connection, groupID, groupIDLength, cacheID, strlen(cacheID), value, strlen(value), (time_t)expireSec, 0);
    else
        rc = memcached_set(connection, cacheID, strlen(cacheID), value, strlen(value), (time_t)expireSec, 0);
    
    assertOnError(rc, "'Set' request failed - ");
    return rc == MEMCACHED_NOTFOUND ? ESPCacheNotFound : (rc == MEMCACHED_SUCCESS ? ESPCacheSuccess : ESPCacheError);
}
Exemple #2
0
/* added by Wakamori */
static void memcached_vsyslog(int p, const char *fmt, va_list ap)
{
	if(memc != NULL) {
		/* gettime */
		char date[256];
		time_t t;
		struct tm tm;
		time(&t);
#if defined(K_USING_WINDOWS_)
#if defined(K_USING_MINGW_)
		tm = *localtime(&t);
#else
		localtime_s(&tm, &t);
#endif /* defined(K_USING_MINGW_) */
#else
		localtime_r(&t, &tm);
#endif /* defined(K_USING_WINDOWS_) */
		knh_format_w3cdtf(date, 255, &tm);

		/* gethostname */
		char host[256];
		gethostname(host, 255);

		/* getpid */
		pid_t pid = getpid();

		char buf[K_LOG_msgSIZE];
		vsnprintf(buf, sizeof(buf), fmt, ap);
		const char *key = (const char *)buf;
		char *ptr = strchr(key, ' ');
		size_t key_len = ptr - key;

		const char *gkey = ptr + 1;
		ptr = strchr(gkey, ' ');
		size_t gkey_len = ptr - gkey;

		/* format log */
		char log[K_LOG_msgSIZE];
		snprintf(log, K_LOG_msgSIZE, "%s %s konoha[%d]: %s", date, host, pid, buf);
		//fprintf(stderr, "log=%s\n", log);

		memcached_return rc;
		time_t expire = 30 * 60; /* 30 minutes */
		rc = memcached_set_by_key(memc, gkey, gkey_len, key, key_len, log, strlen(log), expire, 0);
		DBG_ASSERT(rc == MEMCACHED_SUCCESS);
	}
}
 /**
  * Writes an object to a server specified by the master_key parameter.
  * If the object already exists, it will overwrite the existing object.
  *
  * @param[in] master_key key that specifies server to write to
  * @param[in] key key of object to write to server
  * @param[in] value value of object to write to server
  * @param[in] expiration time to keep the object stored in the server for
  * @param[in] flags flags to store with the object
  * @return true on succcess; false otherwise
  */
 bool setByKey(const std::string &master_key, 
               const std::string &key, 
               const std::vector<char> &value,
               time_t expiration,
               uint32_t flags)
 {
   if (master_key.empty() ||
       key.empty() ||
       value.empty())
   {
     return false;
   }
   memcached_return rc= memcached_set_by_key(&memc, master_key.c_str(), 
                                             master_key.length(),
                                             key.c_str(), key.length(),
                                             &value[0], value.size(),
                                             expiration,
                                             flags);
   return (rc == MEMCACHED_SUCCESS);
 }
Exemple #4
0
  return (rc == MEMCACHED_SUCCESS ? 0 : 1);
}

long long memc_set_by_key(UDF_INIT *initid, UDF_ARGS *args,
                   __attribute__ ((unused)) char *is_null,
                   char *error)
{
  memcached_return rc;
  memc_function_st *container= (memc_function_st *)initid->ptr;

  fix_null_args(args, 3);

  rc= memcached_set_by_key(container->memc,
                           args->args[0], (size_t)args->lengths[0],
                           args->args[1], (size_t)args->lengths[1],
                           args->args[2], (size_t)args->lengths[2],
                           container->expiration, (uint16_t)0);
  if (rc != MEMCACHED_SUCCESS)
  {
    log_error(args, "memcached_set_by_key failed, rc=%d\n", rc);
    return (long long)0;  
  }

  return (long long) 1;
}

void memc_set_by_key_deinit(UDF_INIT *initid)
{
  /* if we allocated initid->ptr, free it here */
  memc_function_st *container= (memc_function_st *)initid->ptr;