예제 #1
0
int memcached_append_value(char *key, size_t key_len, char *value, size_t value_len, uint32_t flag)
{
	if (memcached_connected == -1)
	{
		if (memcached_connect_to_server("127.0.0.1", 11211) == -1)
			return -1;
	}
	memcached_return rc;
	rc = memcached_append(memc, key, key_len, value, value_len, 0, flag);
	if (rc == MEMCACHED_SUCCESS)
		return 0;
	return -1;
}
예제 #2
0
 /**
  * Places a segment of data at the end of the last piece of data stored.
  *
  * @param[in] key key of object whose value we will append data to
  * @param[in] value data to append to object's value
  * @return true on success; false otherwise
  */
 bool append(const std::string &key, const std::vector<char> &value)
 {
   if (key.empty() || value.empty())
   {
     return false;
   }
   memcached_return rc= memcached_append(&memc, 
                                         key.c_str(), 
                                         key.length(),
                                         &value[0], 
                                         value.size(), 
                                         0, 0);
   return (rc == MEMCACHED_SUCCESS);
 }
예제 #3
0
static int
exec_append(memcached_st *mcd, const char *key, const char *value,
			 time_t expire, uint32_t flags)
{
	memcached_return_t  error = memcached_append(mcd, key, strlen(key),
												 value, strlen(value),
												 expire, flags);
	if (error == MEMCACHED_SUCCESS)
		printf("append: key=%s value=%s expire=%lu flags=%u\n",
			   key, value, expire, flags);
	else
		printf("append: key=%s error=%s\n",
			   key, memcached_strerror(mcd, error));
	return 0;
}
예제 #4
0
/**
 * @function memcached.append
 * 
 * ### Synopsis
 * 
 * var rc = memcached.append(handle, key, value);
 * var rc = memcached.append(handle, key, value, expiration);
 * var rc = memcached.append(handle, key, value, expiration, flags);
 * 
 * Appends the given value string to the value of an existing item.  
 * 
 * If an object identified by key does not exist, an error occurs.
 * 
 * @param {object} handle - handle to memcached connection.
 * @param {string} key - key of data to set in memcached.
 * @param {string} value - value of data to append in memcached.
 * @param {int} expiration - length of time value is valid (after this it will be removed from memcached automatically).
 * @param {int} flags - user defined integer value stored along with the value.
 * @return {int} rc - result code; 0 if no error, otherwise the error code.
 */
JSVAL _memcached_append (JSARGS args) {
    HandleScope scope;
    M *handle = HANDLE(args[0]);
    String::Utf8Value key(args[1]);
    String::Utf8Value value(args[2]);
    time_t expiration = 0;
    if (args.Length() > 3) {
        expiration = args[3]->IntegerValue();
    }
    uint32_t flags = 0;
    if (args.Length() > 4) {
        flags = args[4]->IntegerValue();
    }
    return scope.Close(Integer::New(memcached_append(handle, *key, strlen(*key), *value, strlen(*value), expiration, flags)));
}
예제 #5
0
파일: IoMemcached.c 프로젝트: ADTSH/io
/*doc Memcached append(key, value)
Asks memcached to add this value to an existing key after existing value.
Returns true on success, otherwise raises an exception.
value should be a Sequence.
Supported by memcached 1.2.4+
*/
IoObject *IoMemcached_append(IoMemcached *self, IoObject *locals, IoMessage *m)
{
	IoSeq *key   = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoSeq *value = IoMessage_locals_seqArgAt_(m, locals, 1);

	memcached_return_t rc;
	rc = memcached_append(DATA(self)->mc,
		CSTRING(key),   IOSEQ_LENGTH(key),
		CSTRING(value), IOSEQ_LENGTH(value),
		0, 0
	);

	if(rc != MEMCACHED_SUCCESS)
		IoState_error_(IOSTATE, m, memcached_strerror(DATA(self)->mc, rc));

	return IOSTATE->ioTrue;
}
예제 #6
0
VALUE mc_append(VALUE self, VALUE key, VALUE value) {
  memcached_st *mc;
  static memcached_return_t result;

  Data_Get_Struct(self, memcached_st, mc);

  key = StringValue(key);
  if (!use_binary(mc)) key = escape_key(key, NULL);
  value = StringValue(value);

  result = memcached_append(mc, RSTRING_PTR(key), RSTRING_LEN(key), RSTRING_PTR(value), RSTRING_LEN(value), 0, 0);

  if (result == MEMCACHED_SUCCESS) {
    return Qtrue;
  } else if(result == MEMCACHED_NOTSTORED) {
    return Qfalse;
  } else {
    return throw_error(&result);
  }
}
예제 #7
0
Memcache_Res CMemcache:: Memcac_Append(string strKey, const char* pValue, size_t val_size, time_t expiration)
{
	Memcache_Res mRes 	= MEMCACHED_SUCCESS;

	if(strKey.empty() || NULL == pValue)
		return static_cast<Memcache_Res>(MEMCACHED_INVALID_ARGUMENTS);

	// lock and append
	pthread_mutex_lock(&m_hmc_mutex);
	if(NULL == m_hMc)
	{
		pthread_mutex_unlock(&m_hmc_mutex);
		return MEMCACHED_SERVER_ERROR;
	}
	
	mRes = memcached_append(m_hMc, strKey.c_str(), strKey.length(), pValue, val_size, expiration, 0);
	if(MEMCACHED_NOTSTORED == mRes)
		mRes = memcached_add(m_hMc, strKey.c_str(), strKey.length(), pValue, val_size, expiration, 0);
	pthread_mutex_unlock(&m_hmc_mutex);

	return mRes;
}