/[projects]/misc/memcached/memc.c
ViewVC logotype

Annotation of /misc/memcached/memc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 637 - (hide annotations) (download)
Mon Mar 29 09:34:16 2010 UTC (14 years, 2 months ago) by torben
File MIME type: text/plain
File size: 746 byte(s)
Added memcached sample
1 torben 637 #include <stdio.h>
2     #include <string.h>
3     #include <time.h>
4     #include <libmemcached/memcached.h>
5    
6     const int PORT = 11211;
7     const int TIMEOUT = 60;
8    
9     int main() {
10     memcached_st memc;
11     memcached_create( &memc );//init structure
12    
13     memcached_server_add(&memc, "localhost", PORT);
14    
15     const char* key = "mykey";
16    
17     srand(time(0));
18    
19     char value[256];
20     sprintf(value,"This is the cached value %i", rand() );
21    
22     memcached_set(&memc, key, strlen(key), value, strlen(value)+1, TIMEOUT, 0); //the +1 is just to include trailing \0
23     printf("wrote: %s\n", value);
24    
25     unsigned int size;
26     unsigned int flags;
27     memcached_return errors;
28     char* returned = memcached_get(&memc, key, strlen(key), &size, &flags, &errors);
29    
30     printf("Returned: %s\n", returned);
31    
32     return 0;
33     }

  ViewVC Help
Powered by ViewVC 1.1.20