1 .TH "LIBMEMCACHED_EXAMPLES" "3" "September 09, 2011" "0.52" "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
54 by making use of \fBmemcached_create_with_options()\fP.
55 .SH CREATING A POOL OF SERVERS
63 Creating a pool of Servers:
67 const char *config_string= "\-\-SERVER=host10.example.com \-\-SERVER=host11.example.com \-\-SERVER=host10.example.com";
69 memcached_pool_st* pool= memcached_pool(config_string, strlen(config_string));
71 memcached_return_t rc;
73 memcached_st *memc= memcached_pool_pop(pool, false, &rc);
78 Release the memc_ptr that was pulled from the pool
80 memcached_pool_push(pool, memc);
85 memcached_pool_destroy(pool);
89 In the above code you create a \fBmemcached_pool_st\fP object with three
90 server by making use of \fBmemcached_pool()\fP.
92 When \fBmemcached_pool_destroy()\fP all memory will be released that is associated
94 .SH ADDING A VALUE TO THE SERVER
102 Adding a value to the Server:
107 char *value= "value";
109 memcached_return_t rc= memcached_set(memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0);
111 if (rc != MEMCACHED_SUCCESS)
113 \&... // handle failure
118 It is best practice to always look at the return value of any operation.
119 .SH FETCHING MULTIPLE VALUES
123 memcached_return_t rc;
124 char *keys[]= {"fudge", "son", "food"};
125 size_t key_length[]= {5, 3, 4};
129 char return_key[MEMCACHED_MAX_KEY];
130 size_t return_key_length;
132 size_t return_value_length;
134 rc= memcached_mget(memc, keys, key_length, 3);
137 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
138 &return_value_length, &flags, &rc)))
146 Notice that you freed values returned from memcached_fetch(). The define
147 \fBMEMCACHED_MAX_KEY\fP is provided for usage.
150 To find out more information please check:
151 \fI\%http://libmemcached.org/\fP
158 2011, Brian Aker DataDifferential, http://datadifferential.com/
159 .\" Generated by docutils manpage writer.