I have just started to experiment with memcached. I googled around and
from the snippest I could find I came up with the following simple
test code:
#include <libmemcached/memcached.h>
#include <stdio.h>
#include <string.h>
int main( int argc, char* argv[] )
{
const char *key = "my_key";
const char *value = "important value";
size_t* len = 0;
char* ret_value;
memcached_return rc;
memcached_st *memc = memcached_create(NULL); // structure used in
talking to memcached server
if( !memc ) {
fprintf(stderr, "ERROR creating memcached structure\n");
}
memcached_server_add( memc, "localhost", MEMCACHED_DEFAULT_PORT );
printf("Adding value\n");
rc = memcached_set( memc,
key, strlen(key),
value, strlen(value),
(time_t)0,
// time to live
(uint32_t)0
// no flags
);
if ( rc != MEMCACHED_SUCCESS ) {
fprintf(stderr, "ERROR setting value in memcached!\n");
}
printf("\tDone\n");
printf("Reading the value: \n");
ret_value = memcached_get( memc,
key,
strlen(key), // key to search for
len,
// will hold length of returned value
(uint32_t)0,
// no flags
&rc );
if ( rc != MEMCACHED_SUCCESS ) {
fprintf(stderr, "ERROR getting value in memcached!\n");
}
printf("%d\n", len);
memcached_free(memc);
return 0;
}
When I run this, I get
Adding value
Done
Reading the value:
Segmentation fault
When I use gdb, I get the following message
Program received signal SIGSEGV, Segmentation fault.
0x00132d04 in memcached_fetch () from /usr/lib/libmemcached.so.2
I used memcat and saw that the key,value is actually written on the
servfer. It's just that I have a problem with reading it.
Any help would be much appreciated. Thanks.