/* LibMemcached
- * Copyright (C) 2006-2009 Brian Aker
+ * Copyright (C) 2006-2009 Brian Aker
* All rights reserved.
*
* Use and distribution licensed under the BSD license. See
}
static memcached_return_t memcached_send_binary(memcached_st *ptr,
- const char *master_key,
+ const char *master_key,
size_t master_key_length,
- const char *key,
- size_t key_length,
- const char *value,
- size_t value_length,
+ const char *key,
+ size_t key_length,
+ const char *value,
+ size_t value_length,
time_t expiration,
uint32_t flags,
uint64_t cas,
memcached_storage_action_t verb);
-static inline memcached_return_t memcached_send(memcached_st *ptr,
- const char *master_key, size_t master_key_length,
- const char *key, size_t key_length,
- const char *value, size_t value_length,
+static inline memcached_return_t memcached_send(memcached_st *ptr,
+ const char *master_key, size_t master_key_length,
+ const char *key, size_t key_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags,
uint64_t cas,
if (cas)
{
- write_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "%s %s%.*s %u %llu %zu %llu%s\r\n",
+ write_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "%s %s%.*s %u %llu %zu %llu%s\r\n",
storage_op_string(verb),
ptr->prefix_key,
- (int)key_length, key, flags,
- (unsigned long long)expiration, value_length,
+ (int)key_length, key, flags,
+ (unsigned long long)expiration, value_length,
(unsigned long long)cas,
(ptr->flags.no_reply) ? " noreply" : "");
}
buffer_ptr= memcpy((buffer_ptr + strlen(command)), ptr->prefix_key, strlen(ptr->prefix_key));
/* Copy in the key, adjust point if a key prefix was used. */
- buffer_ptr= memcpy(buffer_ptr + (ptr->prefix_key ? strlen(ptr->prefix_key) : 0),
+ buffer_ptr= memcpy(buffer_ptr + (ptr->prefix_key ? strlen(ptr->prefix_key) : 0),
key, key_length);
buffer_ptr+= key_length;
- buffer_ptr[0]= ' ';
+ buffer_ptr[0]= ' ';
buffer_ptr++;
write_length= (size_t)(buffer_ptr - buffer);
- write_length+= (size_t) snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "%u %llu %zu%s\r\n",
- flags,
+ write_length+= (size_t) snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "%u %llu %zu%s\r\n",
+ flags,
(unsigned long long)expiration, value_length,
ptr->flags.no_reply ? " noreply" : "");
}
if (rc == MEMCACHED_STORED)
return MEMCACHED_SUCCESS;
- else
+ else
return rc;
error:
}
-memcached_return_t memcached_set(memcached_st *ptr, const char *key, size_t key_length,
- const char *value, size_t value_length,
+memcached_return_t memcached_set(memcached_st *ptr, const char *key, size_t key_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags)
{
memcached_return_t rc;
LIBMEMCACHED_MEMCACHED_SET_START();
- rc= memcached_send(ptr, key, key_length,
+ rc= memcached_send(ptr, key, key_length,
key, key_length, value, value_length,
expiration, flags, 0, SET_OP);
LIBMEMCACHED_MEMCACHED_SET_END();
return rc;
}
-memcached_return_t memcached_add(memcached_st *ptr,
+memcached_return_t memcached_add(memcached_st *ptr,
const char *key, size_t key_length,
- const char *value, size_t value_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags)
{
memcached_return_t rc;
LIBMEMCACHED_MEMCACHED_ADD_START();
- rc= memcached_send(ptr, key, key_length,
+ rc= memcached_send(ptr, key, key_length,
key, key_length, value, value_length,
expiration, flags, 0, ADD_OP);
LIBMEMCACHED_MEMCACHED_ADD_END();
return rc;
}
-memcached_return_t memcached_replace(memcached_st *ptr,
+memcached_return_t memcached_replace(memcached_st *ptr,
const char *key, size_t key_length,
- const char *value, size_t value_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags)
{
memcached_return_t rc;
LIBMEMCACHED_MEMCACHED_REPLACE_START();
- rc= memcached_send(ptr, key, key_length,
+ rc= memcached_send(ptr, key, key_length,
key, key_length, value, value_length,
expiration, flags, 0, REPLACE_OP);
LIBMEMCACHED_MEMCACHED_REPLACE_END();
return rc;
}
-memcached_return_t memcached_prepend(memcached_st *ptr,
+memcached_return_t memcached_prepend(memcached_st *ptr,
const char *key, size_t key_length,
- const char *value, size_t value_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags)
{
memcached_return_t rc;
- rc= memcached_send(ptr, key, key_length,
+ rc= memcached_send(ptr, key, key_length,
key, key_length, value, value_length,
expiration, flags, 0, PREPEND_OP);
return rc;
}
-memcached_return_t memcached_append(memcached_st *ptr,
+memcached_return_t memcached_append(memcached_st *ptr,
const char *key, size_t key_length,
- const char *value, size_t value_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags)
{
memcached_return_t rc;
- rc= memcached_send(ptr, key, key_length,
+ rc= memcached_send(ptr, key, key_length,
key, key_length, value, value_length,
expiration, flags, 0, APPEND_OP);
return rc;
}
-memcached_return_t memcached_cas(memcached_st *ptr,
+memcached_return_t memcached_cas(memcached_st *ptr,
const char *key, size_t key_length,
- const char *value, size_t value_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags,
uint64_t cas)
{
memcached_return_t rc;
- rc= memcached_send(ptr, key, key_length,
+ rc= memcached_send(ptr, key, key_length,
key, key_length, value, value_length,
expiration, flags, cas, CAS_OP);
return rc;
}
-memcached_return_t memcached_set_by_key(memcached_st *ptr,
- const char *master_key __attribute__((unused)),
- size_t master_key_length __attribute__((unused)),
- const char *key, size_t key_length,
- const char *value, size_t value_length,
+memcached_return_t memcached_set_by_key(memcached_st *ptr,
+ const char *master_key __attribute__((unused)),
+ size_t master_key_length __attribute__((unused)),
+ const char *key, size_t key_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags)
{
memcached_return_t rc;
LIBMEMCACHED_MEMCACHED_SET_START();
- rc= memcached_send(ptr, master_key, master_key_length,
+ rc= memcached_send(ptr, master_key, master_key_length,
key, key_length, value, value_length,
expiration, flags, 0, SET_OP);
LIBMEMCACHED_MEMCACHED_SET_END();
return rc;
}
-memcached_return_t memcached_add_by_key(memcached_st *ptr,
+memcached_return_t memcached_add_by_key(memcached_st *ptr,
const char *master_key, size_t master_key_length,
const char *key, size_t key_length,
- const char *value, size_t value_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags)
{
memcached_return_t rc;
LIBMEMCACHED_MEMCACHED_ADD_START();
- rc= memcached_send(ptr, master_key, master_key_length,
+ rc= memcached_send(ptr, master_key, master_key_length,
key, key_length, value, value_length,
expiration, flags, 0, ADD_OP);
LIBMEMCACHED_MEMCACHED_ADD_END();
return rc;
}
-memcached_return_t memcached_replace_by_key(memcached_st *ptr,
+memcached_return_t memcached_replace_by_key(memcached_st *ptr,
const char *master_key, size_t master_key_length,
const char *key, size_t key_length,
- const char *value, size_t value_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags)
{
memcached_return_t rc;
LIBMEMCACHED_MEMCACHED_REPLACE_START();
- rc= memcached_send(ptr, master_key, master_key_length,
+ rc= memcached_send(ptr, master_key, master_key_length,
key, key_length, value, value_length,
expiration, flags, 0, REPLACE_OP);
LIBMEMCACHED_MEMCACHED_REPLACE_END();
return rc;
}
-memcached_return_t memcached_prepend_by_key(memcached_st *ptr,
+memcached_return_t memcached_prepend_by_key(memcached_st *ptr,
const char *master_key, size_t master_key_length,
const char *key, size_t key_length,
- const char *value, size_t value_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags)
{
memcached_return_t rc;
- rc= memcached_send(ptr, master_key, master_key_length,
+ rc= memcached_send(ptr, master_key, master_key_length,
key, key_length, value, value_length,
expiration, flags, 0, PREPEND_OP);
return rc;
}
-memcached_return_t memcached_append_by_key(memcached_st *ptr,
+memcached_return_t memcached_append_by_key(memcached_st *ptr,
const char *master_key, size_t master_key_length,
const char *key, size_t key_length,
- const char *value, size_t value_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags)
{
memcached_return_t rc;
- rc= memcached_send(ptr, master_key, master_key_length,
+ rc= memcached_send(ptr, master_key, master_key_length,
key, key_length, value, value_length,
expiration, flags, 0, APPEND_OP);
return rc;
}
-memcached_return_t memcached_cas_by_key(memcached_st *ptr,
+memcached_return_t memcached_cas_by_key(memcached_st *ptr,
const char *master_key, size_t master_key_length,
const char *key, size_t key_length,
- const char *value, size_t value_length,
+ const char *value, size_t value_length,
time_t expiration,
uint32_t flags,
uint64_t cas)
{
memcached_return_t rc;
- rc= memcached_send(ptr, master_key, master_key_length,
+ rc= memcached_send(ptr, master_key, master_key_length,
key, key_length, value, value_length,
expiration, flags, cas, CAS_OP);
return rc;
static memcached_return_t memcached_send_binary(memcached_st *ptr,
- const char *master_key,
+ const char *master_key,
size_t master_key_length,
const char *key,
- size_t key_length,
- const char *value,
- size_t value_length,
+ size_t key_length,
+ const char *value,
+ size_t value_length,
time_t expiration,
uint32_t flags,
uint64_t cas,
uint8_t flush;
protocol_binary_request_set request= {.bytes= {0}};
size_t send_length= sizeof(request.bytes);
- uint32_t server_key= memcached_generate_hash(ptr, master_key,
+ uint32_t server_key= memcached_generate_hash(ptr, master_key,
master_key_length);
memcached_server_st *server= &ptr->hosts[server_key];
bool noreply= server->root->flags.no_reply;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
if (verb == APPEND_OP || verb == PREPEND_OP)
send_length -= 8; /* append & prepend does not contain extras! */
- else
+ else
{
request.message.header.request.extlen= 8;
- request.message.body.flags= htonl(flags);
+ request.message.body.flags= htonl(flags);
request.message.body.expiration= htonl((uint32_t)expiration);
}
- request.message.header.request.bodylen= htonl((uint32_t) (key_length + value_length +
+ request.message.header.request.bodylen= htonl((uint32_t) (key_length + value_length +
request.message.header.request.extlen));
if (cas)
/* write the header */
if ((memcached_do(server, (const char*)request.bytes, send_length, 0) != MEMCACHED_SUCCESS) ||
(memcached_io_write(server, key, key_length, 0) == -1) ||
- (memcached_io_write(server, value, value_length, (char) flush) == -1))
+ (memcached_io_write(server, value, value_length, (char) flush) == -1))
{
memcached_io_reset(server);
return MEMCACHED_WRITE_FAILURE;
}
- unlikely (verb == SET_OP && ptr->number_of_replicas > 0)
+ unlikely (verb == SET_OP && ptr->number_of_replicas > 0)
{
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_SETQ;
server_key= 0;
memcached_server_st *srv= &ptr->hosts[server_key];
- if ((memcached_do(srv, (const char*)request.bytes,
+ if ((memcached_do(srv, (const char*)request.bytes,
send_length, 0) != MEMCACHED_SUCCESS) ||
(memcached_io_write(srv, key, key_length, 0) == -1) ||
(memcached_io_write(srv, value, value_length, (char) flush) == -1))
if (noreply)
return MEMCACHED_SUCCESS;
- return memcached_response(server, NULL, 0, NULL);
+ return memcached_response(server, NULL, 0, NULL);
}