Esempio n. 1
0
 /**
  * Places a segment of data before the last piece of data stored.
  *
  * @param[in] key key of object whose value we will prepend data to
  * @param[in] value data to prepend to object's value
  * @return true on success; false otherwise
  */
 bool prepend(const std::string &key, const std::vector<char> &value)
 {
   if (key.empty() || value.empty())
   {
     return false;
   }
   memcached_return rc= memcached_prepend(&memc, key.c_str(), key.length(),
                                          &value[0], value.size(), 0, 0);
   return (rc == MEMCACHED_SUCCESS);
 }
Esempio n. 2
0
/**
 * @function memcached.prepend
 * 
 * ### Synopsis
 * 
 * var rc = memcached.prepend(handle, key, value);
 * var rc = memcached.prepend(handle, key, value, expiration);
 * var rc = memcached.prepend(handle, key, value, expiration, flags);
 * 
 * Prepends 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 prepend 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_prepend (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_prepend(handle, *key, strlen(*key), *value, strlen(*value), expiration, flags)));
}
Esempio n. 3
0
/*doc Memcached prepend(key, value)
Asks memcached to add this value to an existing key before existing value.
Returns true on success, otherwise raises an exception.
value should be a Sequence.
Supported by memcached 1.2.4+
*/
IoObject *IoMemcached_prepend(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_prepend(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;
}
Esempio n. 4
0
Memcache_Res CMemcache:: Memcac_Prepend(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 prepend
	pthread_mutex_lock(&m_hmc_mutex);
	if(NULL == m_hMc)
		return MEMCACHED_SERVER_ERROR;
	
	mRes = memcached_prepend(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;
}
Esempio n. 5
0
VALUE mc_prepend(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_prepend(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);
  }
}
Esempio n. 6
0
	virtual void execute(memcached_st* mem) {
		this->debug && printf("%s %s (%zu): %s (%zu)\n", "PrependJob execute", key.c_str(), key.size(), value.c_str(), value.size());
		rc = memcached_prepend(mem, key.c_str(), key.size(), value.c_str(), value.size(), 0, (uint32_t)0);
	}
Esempio n. 7
0
  rc= memc_get_servers(&container->memc);

  initid->ptr= (char *)container;

  return 0;
}

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

  rc= memcached_prepend(&container->memc,
                        args->args[0], (size_t)args->lengths[0],
                        args->args[1], (size_t)args->lengths[1],
                        container->expiration, (uint16_t)0);

  return ((long long)rc);
}

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

  memcached_free(&container->memc);
  free(container);
}

my_bool memc_prepend_by_key_init(UDF_INIT *initid, UDF_ARGS *args, char *message)