1 .TH "LIBMEMCACHED_EXAMPLES" "3" "April 12, 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 CREATING AND FREEING THE MEMCACHED_ST STRUCTURE
45 memcached_return_t rc;
47 memc= memcached_create(NULL);
53 The above code would create a connection and then free the connection when
55 .SH CONNECTING TO SERVERS
59 const char *config_string= "\-\-SERVER=host10.example.com \-\-SERVER=host11.example.com \-\-SERVER=host10.example.com"
60 memcached_st *memc= memcached_create_with_options(config_string, strlen(config_string);
68 In the above code you create a \fBmemcached_st\fP object with three server by making use of \fImemcached_create_with_options(3)\fP.
69 .SH CREATING A POOL OF SERVERS
73 const char *config_string= "\-\-SERVER=host10.example.com \-\-SERVER=host11.example.com \-\-SERVER=host10.example.com";
75 memcached_pool_st* pool= memcached_pool(config_string, strlen(config_string));
77 memcached_return_t rc;
79 memcached_st *memc= memcached_pool_pop(pool, false, &rc);
84 Release the memc_ptr that was pulled from the pool
86 memcached_pool_push(pool, memc);
91 memcached_pool_destroy(pool);
95 In the above code you create a \fBmemcached_pool_st\fP object with three
96 server by making use of \fImemcached_pool(3)\fP.
98 When memcached_pool_destroy() all memory will be released that is associated
100 .SH ADDING A VALUE TO THE SERVER
106 size_t value_length= 8191;
109 value = (char*)malloc(value_length);
112 for (x= 0; x < value_length; x++)
113 value[x] = (char) (x % 127);
115 for (x= 0; x < 1; x++)
117 rc= memcached_set(memc, key, strlen(key),
119 (time_t)0, (uint32_t)0);
120 assert(rc == MEMCACHED_SUCCESS);
127 It is best practice to always look at the return value of any operation.
128 .SH FETCHING MULTIPLE VALUES
132 memcached_return_t rc;
133 char *keys[]= {"fudge", "son", "food"};
134 size_t key_length[]= {5, 3, 4};
138 char return_key[MEMCACHED_MAX_KEY];
139 size_t return_key_length;
141 size_t return_value_length;
143 rc= memcached_mget(memc, keys, key_length, 3);
146 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
147 &return_value_length, &flags, &rc)))
155 Notice that you freed values returned from memcached_fetch(). The define
156 \fBMEMCACHED_MAX_KEY\fP is provided for usage.
159 To find out more information please check:
160 \fI\%https://launchpad.net/libmemcached\fP
167 2011, Brian Aker DataDifferential, http://datadifferential.com/
168 .\" Generated by docutils manpage writer.