В rc хранится результат последней операции (успешно или нет).
1 #include <stdio.h>
2 #include <string.h>
3
4 #include <libmemcached/memcached.h>
5
6 int main(int argc, char** argv)
7 {
8 /* Basic libmemcached structures */
9 memcached_st *mc = NULL;
10 memcached_stat_st *mc_st = NULL;
11 memcached_return rc;
12
13 /* Server information: */
14 /*const*/ char hostname[]="localhost";
15 /*const*/ unsigned int port = 11211;
16 /*const*/ char args[] = "";
17
18 /* To set: */
19 /*const*/ char key[] = "my_key";
20 /*const*/ char value[] = "my_value";
21
22 /* To get: */
23 /*const*/ char key_r[] = "my_key";
24 char* res = NULL;
25 size_t ressize = 0;
26 uint32_t flags;
27
28 /* Let's do it */
29 mc = memcached_create (NULL);
30 rc = memcached_server_add(mc, hostname, port);
31 mc_st = memcached_stat (mc, args, &rc);
32 rc = memcached_set (mc, key, strlen(key),
33 value, strlen(value), 0, 0);
34 res = memcached_get (mc, key_r, strlen(key_r),
35 &ressize, &flags, &rc);
36 rc = memcached_flush(mc, /* Now */ 0);
37
38 /* Output results */
39 printf( "Welcome to libmemcached sample program!\n"
40 "Version of the memcached server is:\t%s\n"
41 "The pair (key => value) "
42 "have been set:\t(%s => %s)\n"
43 "The value associated with key\t\t%s\n"
44 "have been read. The value is:\t\t%s\n",
45 mc_st->version, key, value, key_r, res);
46
47 /* Clean up */
48 if (mc) memcached_free(mc);
49 if (mc_st) free(mc_st);
50 if (res) free(res);
51 return 0;
52 }