1 .TH "LIBMEMCACHED_EXAMPLES" "3" "April 13, 2011" "0.47" "libmemcached"
3 libmemcached_examples \- libmemcached Documentation
5 .nr rst2man-indent-level 0
9 level \\n[rst2man-indent-level]
10 level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
17 .\" .rstReportMargin pre:
19 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
20 . nr rst2man-indent-level +1
21 .\" .rstReportMargin post:
25 .\" indent \\n[an-margin]
26 .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
27 .nr rst2man-indent-level -1
28 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
29 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
31 .\" Man page generated from reStructeredText.
34 Examples for libmemcached
37 For full examples, test cases are found in tests/*.c in the main
38 distribution. These are always up to date, and are used for each test run of
40 .SH CONNECTING TO SERVERS
44 const char *config_string= "\-\-SERVER=host10.example.com \-\-SERVER=host11.example.com \-\-SERVER=host10.example.com"
45 memcached_st *memc= memcached(config_string, strlen(config_string);
53 In the above code you create a \fBmemcached_st\fP object with three server by making use of \fImemcached_create_with_options(3)\fP.
54 .SH CREATING A POOL OF SERVERS
58 const char *config_string= "\-\-SERVER=host10.example.com \-\-SERVER=host11.example.com \-\-SERVER=host10.example.com";
60 memcached_pool_st* pool= memcached_pool(config_string, strlen(config_string));
62 memcached_return_t rc;
64 memcached_st *memc= memcached_pool_pop(pool, false, &rc);
69 Release the memc_ptr that was pulled from the pool
71 memcached_pool_push(pool, memc);
76 memcached_pool_destroy(pool);
80 In the above code you create a \fBmemcached_pool_st\fP object with three
81 server by making use of \fImemcached_pool(3)\fP.
83 When memcached_pool_destroy() all memory will be released that is associated
85 .SH ADDING A VALUE TO THE SERVER
92 memcached_return_t rc= memcached_set(memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0);
94 if (rc != MEMCACHED_SUCCESS)
96 \&... // handle failure
101 It is best practice to always look at the return value of any operation.
102 .SH FETCHING MULTIPLE VALUES
106 memcached_return_t rc;
107 char *keys[]= {"fudge", "son", "food"};
108 size_t key_length[]= {5, 3, 4};
112 char return_key[MEMCACHED_MAX_KEY];
113 size_t return_key_length;
115 size_t return_value_length;
117 rc= memcached_mget(memc, keys, key_length, 3);
120 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
121 &return_value_length, &flags, &rc)))
129 Notice that you freed values returned from memcached_fetch(). The define
130 \fBMEMCACHED_MAX_KEY\fP is provided for usage.
133 To find out more information please check:
134 \fI\%https://launchpad.net/libmemcached\fP
141 2011, Brian Aker DataDifferential, http://datadifferential.com/
142 .\" Generated by docutils manpage writer.