5 Examples for libmemcached
12 For full examples, test cases are found in tests/\*.c in the main
13 distribution. These are always up to date, and are used for each test run of
24 const char *config_string= "--SERVER=host10.example.com --SERVER=host11.example.com --SERVER=host10.example.com"
25 memcached_st *memc= memcached(config_string, strlen(config_string);
32 In the above code you create a \ ``memcached_st``\ object with three server by making use of :manpage:`memcached_create_with_options(3)`.
35 --------------------------
36 Creating a pool of servers
37 --------------------------
43 const char *config_string= "--SERVER=host10.example.com --SERVER=host11.example.com --SERVER=host10.example.com";
45 memcached_pool_st* pool= memcached_pool(config_string, strlen(config_string));
47 memcached_return_t rc;
49 memcached_st *memc= memcached_pool_pop(pool, false, &rc);
54 Release the memc_ptr that was pulled from the pool
56 memcached_pool_push(pool, memc);
61 memcached_pool_destroy(pool);
65 In the above code you create a \ ``memcached_pool_st``\ object with three
66 server by making use of :manpage:`memcached_pool(3)`.
68 When memcached_pool_destroy() all memory will be released that is associated
72 ----------------------------
73 Adding a value to the server
74 ----------------------------
83 memcached_return_t rc= memcached_set(memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0);
85 if (rc != MEMCACHED_SUCCESS)
91 It is best practice to always look at the return value of any operation.
94 ------------------------
95 Fetching multiple values
96 ------------------------
102 memcached_return_t rc;
103 char *keys[]= {"fudge", "son", "food"};
104 size_t key_length[]= {5, 3, 4};
108 char return_key[MEMCACHED_MAX_KEY];
109 size_t return_key_length;
111 size_t return_value_length;
113 rc= memcached_mget(memc, keys, key_length, 3);
116 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
117 &return_value_length, &flags, &rc)))
124 Notice that you freed values returned from memcached_fetch(). The define
125 \ ``MEMCACHED_MAX_KEY``\ is provided for usage.
134 To find out more information please check:
135 `http://libmemcached.org/ <http://libmemcached.org/>`_
143 :manpage:`memcached(1)`