Multi host support added.
New code for stats (and we now fetch stats array)
Further library split.
AC_INIT(src/main.c)\r
AC_CONFIG_AUX_DIR(config)\r
AM_CONFIG_HEADER(config.h)\r
-AM_INIT_AUTOMAKE("?", 0.1 )\r
+AM_INIT_AUTOMAKE("?", 0.2 )\r
\r
AC_PROG_CC\r
AC_PROG_LIBTOOL\r
MEMCACHED_NOTFOUND,
MEMCACHED_MEMORY_ALLOCATION_FAILURE,
MEMCACHED_PARTIAL_READ,
+ MEMCACHED_SOME_ERRORS,
} memcached_return;
typedef enum {
uint16_t flags);
memcached_return memcached_delete(memcached_st *ptr, char *key, size_t key_length,
time_t expiration);
-memcached_return memcached_increment(memcached_st *ptr, char *key, size_t key_length,
- unsigned int count);
-memcached_return memcached_decrement(memcached_st *ptr, char *key, size_t key_length,
- unsigned int count);
-memcached_stat_st **memcached_stat(memcached_st *ptr, memcached_return *error);
+memcached_return memcached_increment(memcached_st *ptr,
+ char *key, size_t key_length,
+ unsigned int offset,
+ unsigned int *value);
+memcached_return memcached_decrement(memcached_st *ptr,
+ char *key, size_t key_length,
+ unsigned int offset,
+ unsigned int *value);
+memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return *error);
memcached_return memcached_stat_hostname(memcached_stat_st *stat, char *args,
char *hostname, unsigned int port);
memcached_return memcached_flush(memcached_st *ptr, time_t expiration);
/* These are all private, do not use. */
memcached_return memcached_connect(memcached_st *ptr);
memcached_return memcached_response(memcached_st *ptr,
- char *buffer,
- size_t buffer_length);
+ char *buffer, size_t buffer_length,
+ unsigned int server_key);
+unsigned int memcached_generate_hash(char *key, size_t key_length);
#ifdef __cplusplus
}
memcached_get.c \\r
memcached_storage.c \\r
memcached_delete.c \\r
+ memcached_hash.c \\r
+ memcached_auto.c \\r
+ memcached_verbosity.c \\r
+ memcached_quit.c \\r
+ memcached_flush.c \\r
memcached_stats.c\r
return ptr;
}
-memcached_return memcached_increment(memcached_st *ptr, char *key, size_t key_length,
- unsigned int count)
-{
- return MEMCACHED_SUCCESS;
-}
-
-memcached_return memcached_decrement(memcached_st *ptr, char *key, size_t key_length,
- unsigned int count)
-{
- return MEMCACHED_SUCCESS;
-}
-
-memcached_return memcached_flush(memcached_st *ptr, time_t expiration)
-{
- size_t send_length;
- memcached_return rc;
- char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-
- rc= memcached_connect(ptr);
-
- if (expiration)
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "flush_all %u\r\n", expiration);
- else
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "flush_all\r\n");
- if ((send(ptr->hosts[0].fd, buffer, send_length, 0) == -1))
- {
- fprintf(stderr, "failed flush_all TCP\n");
-
- return MEMCACHED_WRITE_FAILURE;
- }
-
- return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
-}
-
-memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity)
-{
- size_t send_length;
- memcached_return rc;
- char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-
- rc= memcached_connect(ptr);
-
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "verbosity %u\r\n", verbosity);
-
- if ((send(ptr->hosts[0].fd, buffer, send_length, 0) == -1))
- {
- fprintf(stderr, "failed verbosity\n");
-
- return MEMCACHED_WRITE_FAILURE;
- }
-
- return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
-}
-
-/*
- When this is implemented you will be able to remove single hosts
- from your current pool of hosts.
-*/
-memcached_return memcached_quit(memcached_st *ptr, char *hostname, unsigned port)
-{
- return MEMCACHED_SUCCESS;
-}
-
void memcached_deinit(memcached_st *ptr)
{
unsigned int x;
else
memset(ptr, 0, sizeof(memcached_st));
}
-
-char *memcached_strerror(memcached_st *ptr, memcached_return rc)
-{
- switch (rc)
- {
- case MEMCACHED_SUCCESS:
- return "SUCCESS";
- case MEMCACHED_FAILURE:
- return "FAILURE";
- case MEMCACHED_HOST_LOCKUP_FAILURE:
- return "HOSTNAME LOOKUP FAILURE";
- case MEMCACHED_CONNECTION_FAILURE:
- return "CONNECTION FAILURE";
- case MEMCACHED_CONNECTION_BIND_FAILURE:
- return "CONNECTION BIND FAILURE";
- case MEMCACHED_READ_FAILURE:
- return "READ FAILURE";
- case MEMCACHED_UNKNOWN_READ_FAILURE:
- return "UNKNOWN READ FAILURE";
- case MEMCACHED_PROTOCOL_ERROR:
- return "PROTOCOL ERROR";
- case MEMCACHED_CLIENT_ERROR:
- return "CLIENT ERROR";
- case MEMCACHED_SERVER_ERROR:
- return "SERVER ERROR";
- case MEMCACHED_WRITE_FAILURE:
- return "WRITE FAILURE";
- case MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE:
- return "CONNECTION SOCKET CREATE FAILURE";
- case MEMCACHED_DATA_EXISTS:
- return "CONNECTION DATA EXISTS";
- case MEMCACHED_DATA_DOES_NOT_EXIST:
- return "CONNECTION DATA DOES NOT EXIST";
- case MEMCACHED_NOTSTORED:
- return "NOT STORED";
- case MEMCACHED_NOTFOUND:
- return "NOT FOUND";
- case MEMCACHED_MEMORY_ALLOCATION_FAILURE:
- return "MEMORY ALLOCATION FAILURE";
- case MEMCACHED_PARTIAL_READ:
- return "PARTIAL READ";
- };
-}
--- /dev/null
+#include <memcached.h>
+
+static memcached_return memcached_auto(memcached_st *ptr,
+ char *verb,
+ char *key, size_t key_length,
+ unsigned int offset,
+ unsigned int *value)
+{
+ size_t send_length;
+ memcached_return rc;
+ char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
+ unsigned int server_key;
+
+ rc= memcached_connect(ptr);
+
+ if (rc != MEMCACHED_SUCCESS)
+ return rc;
+
+ server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts;
+
+ send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "%s %.*s %u\r\n", verb,
+ key_length, key,
+ offset);
+
+ if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1))
+ {
+ fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
+
+ return MEMCACHED_WRITE_FAILURE;
+ }
+
+ memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE);
+ send_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
+
+ if (!memcmp(buffer, "ERROR\r\n", MEMCACHED_DEFAULT_COMMAND_SIZE))
+ {
+ *value= 0;
+ rc= MEMCACHED_PROTOCOL_ERROR;
+ }
+ else if (!memcmp(buffer, "NOT_FOUND\r\n", MEMCACHED_DEFAULT_COMMAND_SIZE))
+ {
+ *value= 0;
+ rc= MEMCACHED_NOTFOUND;
+ }
+ else
+ {
+ *value= strtol(buffer, (char **)NULL, 10);
+ rc= MEMCACHED_SUCCESS;
+ }
+
+ return rc;
+}
+
+memcached_return memcached_increment(memcached_st *ptr,
+ char *key, size_t key_length,
+ unsigned int offset,
+ unsigned int *value)
+{
+ return memcached_auto(ptr, "incr", key, key_length, offset, value);
+}
+
+memcached_return memcached_decrement(memcached_st *ptr,
+ char *key, size_t key_length,
+ unsigned int offset,
+ unsigned int *value)
+{
+ return memcached_auto(ptr, "decr", key, key_length, offset, value);
+}
size_t send_length;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
+ unsigned int server_key;
rc= memcached_connect(ptr);
+ if (rc != MEMCACHED_SUCCESS)
+ return rc;
+
+ server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts;
+
if (expiration)
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"delete %.*s %u\r\n", key_length, key, expiration);
else
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"delete %.*s\r\n", key_length, key);
- if ((write(ptr->hosts[0].fd, buffer, send_length) == -1))
+ if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
{
fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
return MEMCACHED_WRITE_FAILURE;
}
- return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
+ return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key);
}
--- /dev/null
+#include <memcached.h>
+
+memcached_return memcached_flush(memcached_st *ptr, time_t expiration)
+{
+ unsigned int x;
+ size_t send_length;
+ memcached_return rc;
+ char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
+
+ rc= memcached_connect(ptr);
+
+ if (rc != MEMCACHED_SUCCESS)
+ rc= MEMCACHED_SOME_ERRORS;
+
+ for (x= 0; x < ptr->number_of_hosts; x++)
+ {
+ if (expiration)
+ send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "flush_all %u\r\n", expiration);
+ else
+ send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "flush_all\r\n");
+ if ((send(ptr->hosts[x].fd, buffer, send_length, 0) == -1))
+ {
+ fprintf(stderr, "failed flush_all TCP\n");
+
+ return MEMCACHED_WRITE_FAILURE;
+ }
+
+ rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
+
+ if (rc != MEMCACHED_SUCCESS)
+ rc= MEMCACHED_SOME_ERRORS;
+ }
+
+ return rc;
+}
size_t send_length;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
char *string_ptr;
+ unsigned int server_key;
*error= memcached_connect(ptr);
if (*error != MEMCACHED_SUCCESS)
return NULL;
+ server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts;
+
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "get %.*s\r\n",
key_length, key);
if (*error != MEMCACHED_SUCCESS)
return NULL;
- if ((send(ptr->hosts[0].fd, buffer, send_length, 0) == -1))
+ if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1))
{
fprintf(stderr, "failed fetch on %.*s TCP\n", key_length+1, key);
*error= MEMCACHED_WRITE_FAILURE;
}
memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE);
- *error= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
+ *error= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key);
if (*error == MEMCACHED_SUCCESS)
{
need_to_read= *value_length - need_to_copy;
- read_length= read(ptr->hosts[0].fd, pos_ptr, need_to_read);
+ read_length= read(ptr->hosts[server_key].fd, pos_ptr, need_to_read);
if (read_length != need_to_read)
{
free(value);
--- /dev/null
+#include <memcached.h>
+
+unsigned int memcached_generate_hash(char *key, size_t key_length)
+{
+ unsigned int x = key_length;
+ char *ptr = key;
+ unsigned int value = 0;
+
+ while (x--)
+ {
+ value += *ptr++;
+ value += (value << 10);
+ value ^= (value >> 6);
+ }
+ value += (value << 3);
+ value ^= (value >> 11);
+ value += (value << 15);
+
+ return value == 0 ? 1 : value;
+}
--- /dev/null
+#include <memcached.h>
+
+/*
+ When this is implemented you will be able to remove single hosts
+ from your current pool of hosts.
+*/
+memcached_return memcached_quit(memcached_st *ptr, char *hostname, unsigned port)
+{
+ return MEMCACHED_SUCCESS;
+}
#include <memcached.h>
memcached_return memcached_response(memcached_st *ptr,
- char *buffer, size_t buffer_length)
+ char *buffer, size_t buffer_length,
+ unsigned int server_key)
{
size_t send_length;
memset(buffer, 0, buffer_length);
- send_length= read(ptr->hosts[0].fd, buffer, buffer_length);
+ send_length= read(ptr->hosts[server_key].fd, buffer, buffer_length);
if (send_length)
switch(buffer[0])
}
}
-memcached_stat_st **memcached_stat(memcached_st *ptr, memcached_return *error)
+static memcached_return memcached_stats_fetch(memcached_st *ptr,
+ memcached_stat_st *stat,
+ char *args,
+ unsigned int server_key)
{
- return NULL;
-}
-
-memcached_return memcached_stat_hostname(memcached_stat_st *stat, char *args,
- char *hostname, unsigned int port)
-{
- size_t send_length;
memcached_return rc;
char buffer[HUGE_STRING_LEN];
- memcached_st memc;
-
- memcached_init(&memc);
+ size_t send_length;
- rc= memcached_connect(&memc);
+ rc= memcached_connect(ptr);
if (rc != MEMCACHED_SUCCESS)
return rc;
send_length= snprintf(buffer, HUGE_STRING_LEN,
"stats\r\n");
- if ((send(memc.hosts[0].fd, buffer, send_length, 0) == -1))
+ if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1))
{
fprintf(stderr, "failed on stats\n");
- rc= MEMCACHED_WRITE_FAILURE;
- goto error;
+ return MEMCACHED_WRITE_FAILURE;
}
- rc= memcached_response(&memc, buffer, HUGE_STRING_LEN);
+ rc= memcached_response(ptr, buffer, HUGE_STRING_LEN, 0);
if (rc == MEMCACHED_SUCCESS)
{
}
}
-error:
+ return rc;
+}
+
+memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return *error)
+{
+ unsigned int x;
+ memcached_return rc;
+ memcached_stat_st *stats;
+ rc= memcached_connect(ptr);
+
+ if (rc != MEMCACHED_SUCCESS)
+ {
+ *error= rc;
+ return NULL;
+ }
+
+ stats= (memcached_stat_st *)malloc(sizeof(memcached_st)*(ptr->number_of_hosts+1));
+ if (stats)
+ {
+ *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+ return NULL;
+ }
+ memset(stats, 0, sizeof(memcached_st)*(ptr->number_of_hosts+1));
+
+ for (x= 0; x < ptr->number_of_hosts; x++)
+ {
+ rc= memcached_stats_fetch(ptr, stats+x, args, x);
+ if (rc != MEMCACHED_SUCCESS)
+ rc= MEMCACHED_SOME_ERRORS;
+ }
+
+ *error= x == 0 ? MEMCACHED_SUCCESS : rc;
+ return stats;
+}
+
+memcached_return memcached_stat_hostname(memcached_stat_st *stat, char *args,
+ char *hostname, unsigned int port)
+{
+ size_t send_length;
+ memcached_return rc;
+ char buffer[HUGE_STRING_LEN];
+ memcached_st memc;
+
+ memcached_init(&memc);
+
+ memcached_server_add(&memc, hostname, port);
+
+ rc= memcached_connect(&memc);
+
+ if (rc != MEMCACHED_SUCCESS)
+ return rc;
+
+ rc= memcached_stats_fetch(&memc, stat, args, 0);
+
memcached_deinit(&memc);
return rc;
size_t send_length;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
+ unsigned int server_key;
rc= memcached_connect(ptr);
if (rc != MEMCACHED_SUCCESS)
return rc;
+ server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts;
+
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"%s %.*s %u %u %u\r\n", verb,
key_length, key, flags, expiration, value_length);
- if ((send(ptr->hosts[0].fd, buffer, send_length, 0) == -1))
+ if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1))
{
fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"%.*s\r\n",
value_length, value);
- if ((send(ptr->hosts[0].fd, buffer, send_length, 0) == -1))
+ if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1))
{
fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
return MEMCACHED_WRITE_FAILURE;
}
- send_length= read(ptr->hosts[0].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
+ send_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
if (send_length && buffer[0] == 'S') /* STORED */
return MEMCACHED_SUCCESS;
--- /dev/null
+#include <memached.h>
+
+char *memcached_strerror(memcached_st *ptr, memcached_return rc)
+{
+ switch (rc)
+ {
+ case MEMCACHED_SUCCESS:
+ return "SUCCESS";
+ case MEMCACHED_FAILURE:
+ return "FAILURE";
+ case MEMCACHED_HOST_LOCKUP_FAILURE:
+ return "HOSTNAME LOOKUP FAILURE";
+ case MEMCACHED_CONNECTION_FAILURE:
+ return "CONNECTION FAILURE";
+ case MEMCACHED_CONNECTION_BIND_FAILURE:
+ return "CONNECTION BIND FAILURE";
+ case MEMCACHED_READ_FAILURE:
+ return "READ FAILURE";
+ case MEMCACHED_UNKNOWN_READ_FAILURE:
+ return "UNKNOWN READ FAILURE";
+ case MEMCACHED_PROTOCOL_ERROR:
+ return "PROTOCOL ERROR";
+ case MEMCACHED_CLIENT_ERROR:
+ return "CLIENT ERROR";
+ case MEMCACHED_SERVER_ERROR:
+ return "SERVER ERROR";
+ case MEMCACHED_WRITE_FAILURE:
+ return "WRITE FAILURE";
+ case MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE:
+ return "CONNECTION SOCKET CREATE FAILURE";
+ case MEMCACHED_DATA_EXISTS:
+ return "CONNECTION DATA EXISTS";
+ case MEMCACHED_DATA_DOES_NOT_EXIST:
+ return "CONNECTION DATA DOES NOT EXIST";
+ case MEMCACHED_NOTSTORED:
+ return "NOT STORED";
+ case MEMCACHED_NOTFOUND:
+ return "NOT FOUND";
+ case MEMCACHED_MEMORY_ALLOCATION_FAILURE:
+ return "MEMORY ALLOCATION FAILURE";
+ case MEMCACHED_PARTIAL_READ:
+ return "PARTIAL READ";
+ case MEMCACHED_SOME_ERRORS:
+ return "SOME ERRORS WERE REPORTED ";
+ };
+}
--- /dev/null
+#include <memcached.h>
+
+memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity)
+{
+ unsigned int x;
+ size_t send_length;
+ memcached_return rc;
+ char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
+
+ rc= memcached_connect(ptr);
+
+ if (rc != MEMCACHED_SUCCESS)
+ rc= MEMCACHED_SOME_ERRORS;
+
+ send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "verbosity %u\r\n", verbosity);
+
+ for (x= 0; x < ptr->number_of_hosts; x++)
+ {
+ memcached_return rc;
+
+ if ((send(ptr->hosts[x].fd, buffer, send_length, 0) == -1))
+ {
+ fprintf(stderr, "failed verbosity\n");
+
+ return MEMCACHED_WRITE_FAILURE;
+ }
+
+ rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
+
+ if (rc != MEMCACHED_SUCCESS)
+ rc= MEMCACHED_SOME_ERRORS;
+ }
+
+ return rc;
+}
void set_test(void)
{
memcached_st *memc;
- char *foo;
memcached_return rc;
char *key= "foo";
char *value= "when we sanitize";
value, strlen(value),
(time_t)0, (uint16_t)0);
assert(rc == MEMCACHED_SUCCESS);
- assert(foo);
memcached_deinit(memc);
}
void add_test(void)
{
memcached_st *memc;
- char *foo;
memcached_return rc;
char *key= "foo";
char *value= "when we sanitize";
value, strlen(value),
(time_t)0, (uint16_t)0);
assert(rc == MEMCACHED_NOTSTORED);
- assert(foo);
memcached_deinit(memc);
}
void replace_test(void)
{
memcached_st *memc;
- char *foo;
memcached_return rc;
char *key= "foo";
char *value= "when we sanitize";
value, strlen(value),
(time_t)0, (uint16_t)0);
assert(rc == MEMCACHED_SUCCESS);
- assert(foo);
memcached_deinit(memc);
}
void delete_test(void)
{
memcached_st *memc;
- char *foo;
memcached_return rc;
char *key= "foo";
char *value= "when we sanitize";
value, strlen(value),
(time_t)0, (uint16_t)0);
assert(rc == MEMCACHED_SUCCESS);
- assert(foo);
rc= memcached_delete(memc, key, strlen(key), (time_t)0);
assert(rc == MEMCACHED_SUCCESS);
- assert(foo);
memcached_deinit(memc);
}
void get_test2(void)
{
memcached_st *memc;
- char *foo;
memcached_return rc;
char *key= "foo";
char *value= "when we sanitize";
MEMCACHED_DEFAULT_PORT);
}
+void increment_test(void)
+{
+ memcached_st *memc;
+ unsigned int new_number;
+ memcached_return rc;
+ char *key= "number";
+ char *value= "0";
+
+ memc= memcached_init(NULL);
+ assert(memc);
+ rc= memcached_set(memc, key, strlen(key),
+ value, strlen(value),
+ (time_t)0, (uint16_t)0);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ rc= memcached_increment(memc, key, strlen(key),
+ 1, &new_number);
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(new_number == 1);
+
+ rc= memcached_increment(memc, key, strlen(key),
+ 1, &new_number);
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(new_number == 2);
+
+ memcached_deinit(memc);
+}
+
+void decrement_test(void)
+{
+ memcached_st *memc;
+ unsigned int new_number;
+ memcached_return rc;
+ char *key= "number";
+ char *value= "3";
+
+ memc= memcached_init(NULL);
+ assert(memc);
+ rc= memcached_set(memc, key, strlen(key),
+ value, strlen(value),
+ (time_t)0, (uint16_t)0);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ rc= memcached_decrement(memc, key, strlen(key),
+ 1, &new_number);
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(new_number == 2);
+
+ rc= memcached_decrement(memc, key, strlen(key),
+ 1, &new_number);
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(new_number == 1);
+
+ memcached_deinit(memc);
+}
+
int main(void)
{
/* Clean the server before beginning testing */
get_test2();
stats_hostname_test();
+ increment_test();
+ decrement_test();
+
/* Clean up whatever we might have left */
flush_test();
return 0;