4 Examples for libmemcached
9 For full examples, test cases are found in tests/\*.c in the main distribution.
10 These are always up to date, and are used for each test run of the library.
17 const char *config_string =
18 "--SERVER=host10.example.com "
19 "--SERVER=host11.example.com "
20 "--SERVER=host10.example.com";
21 memcached_st *memc= memcached(config_string, strlen(config_string);
27 In the above code you create a `memcached_st` object with three server by making
28 use of `memcached_create`.
30 Creating a pool of servers
31 --------------------------
35 const char *config_string =
36 "--SERVER=host10.example.com "
37 "--SERVER=host11.example.com "
38 "--SERVER=host10.example.com";
40 memcached_pool_st* pool= memcached_pool(config_string, strlen(config_string));
42 memcached_return_t rc;
44 memcached_st *memc= memcached_pool_pop(pool, false, &rc);
49 Release the memc_ptr that was pulled from the pool
51 memcached_pool_push(pool, memc);
56 memcached_pool_destroy(pool);
58 In the above code you create a `memcached_pool_st` object with three server by
59 making use of `memcached_pool()`.
61 When `memcached_pool_destroy()` all memory will be released that is associated
64 Adding a value to the server
65 ----------------------------
74 memcached_return_t rc = memcached_set(memc,
79 if (rc != MEMCACHED_SUCCESS)
84 It is best practice to always look at the return value of any operation.
86 Fetching multiple values
87 ------------------------
91 memcached_return_t rc;
92 char *keys[]= {"fudge", "son", "food"};
93 size_t key_length[]= {5, 3, 4};
97 char return_key[MEMCACHED_MAX_KEY];
98 size_t return_key_length;
100 size_t return_value_length;
102 rc= memcached_mget(memc, keys, key_length, 3);
105 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
106 &return_value_length, &flags, &rc)))
112 Notice that you freed values returned from memcached_fetch(). The define
113 `MEMCACHED_MAX_KEY` is provided for usage.
118 :manpage:`memcached(1)`