1 Working with memcached pools
2 ============================
7 #include <libmemcachedutil-|libmemcached_version|/pool.h>
8 Compile and link with -lmemcachedutil -lmemcached
10 .. type:: struct memcached_pool_st memcached_pool_st
12 .. function:: memcached_pool_st* memcached_pool(const char *option_string, size_t option_string_length)
14 :param option_string: :doc:`configuration </libmemcached/configuration>` string
15 :param option_string_length: length of `options_string` without any trailing zero byte
16 :returns: allocated and initialized `memcached_pool_st` instance on success or nullptr on failure
18 .. function:: memcached_st* memcached_pool_destroy(memcached_pool_st* pool)
20 :param pool: initialized `memcached_pool_st` instance to free
21 :returns: pointer to the 'master' `memcached_st` instance by legacy
23 .. function:: memcached_st* memcached_pool_fetch(memcached_pool_st* pool, struct timespec* relative_time, memcached_return_t* rc)
25 .. versionadded:: 0.53
26 Synonym for memcached_pool_pop
28 :param pool: initialized `memcached_pool_st` instance
29 :param relative_time: time to block thread and wait for a connection to become available when pool size is exceeded, unless nullptr
30 :param rc: out pointer to `memcached_return_t`
31 :returns: pointer to an available `memcached_st` instance
33 .. function:: memcached_return_t memcached_pool_release(memcached_pool_st* pool, memcached_st* mmc)
35 .. versionadded:: 0.53
36 Synonym for memcached_pool_push.
38 :param pool: initialized `memcached_pool_st` instance
39 :param mmc: the `memcached_st` instance to return to the pool
40 :returns: `memcached_return_t` indicating success
42 .. function:: memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, memcached_behavior_t flag, uint64_t data)
44 :param pool: initialized `memcached_pool_st` instance
45 :param flag: the :doc:`behavior </libmemcached/memcached_behavior>` to change
46 :param value: the value to set for `flag`
47 :returns: `memcached_return_t` indicating success
49 .. function:: memcached_return_t memcached_pool_behavior_get(memcached_pool_st *pool, memcached_behavior_t flag, uint64_t *value)
51 :param pool: initialized `memcached_pool_st` instance
52 :param flag: the :doc:`behavior </libmemcached/memcached_behavior>` to read
53 :param value: out pointer to receive the set value of `flag`
54 :returns: `memcached_return_t` indicating success
56 .. function:: memcached_pool_st* memcached_pool_create(memcached_st* mmc, int initial, int max)
61 .. function:: memcached_st* memcached_pool_pop(memcached_pool_st* pool, bool block, memcached_return_t *rc)
64 Use `memcached_pool_fetch`
66 .. function:: memcached_return_t memcached_pool_push(memcached_pool_st* pool, memcached_st *mmc)
69 Use `memcached_pool_release`
74 `memcached_pool` is used to create a connection pool of objects you may use to
75 remove the overhead of using memcached_clone for short lived `memcached_st`
76 objects. Please see :doc:`../libmemcached/configuration` for details on the
77 format of the configuration string.
79 `memcached_pool_destroy` is used to destroy the connection pool created with
80 `memcached_pool_create` and release all allocated resources. It will return the
81 pointer to the `memcached_st` structure passed as an argument to
82 `memcached_pool_create`, and returns the ownership of the pointer to the caller
83 when created with `memcached_pool_create`, otherwise NULL is returned..
85 `memcached_pool_fetch` is used to fetch a connection structure from the
86 connection pool. The relative_time argument specifies if the function should
87 block and wait for a connection structure to be available if we try to exceed
88 the maximum size. You need to specify time in relative time.
90 `memcached_pool_release` is used to return a connection structure back to the
93 `memcached_pool_behavior_get` and `memcached_pool_behavior_set` is used to
94 get/set behavior flags on all connections in the pool.
96 Both `memcached_pool_release` and `memcached_pool_fetch` are thread safe.
101 `memcached_pool_destroy` returns the pointer (and ownership) to the
102 `memcached_st` structure used to create the pool. If connections are in use it
105 `memcached_pool_pop` returns a pointer to a `memcached_st` structure from the
106 pool (or NULL if an allocation cannot be satisfied).
108 `memcached_pool_release` returns `MEMCACHED_SUCCESS` upon success.
110 `memcached_pool_behavior_get` and `memcached_pool_behavior_get` return
111 `MEMCACHED_SUCCESS` upon success.
113 `memcached_pool_fetch` may return `MEMCACHED_TIMEOUT` if a timeout occurs while
114 waiting for a free `memcached_st` instance, `MEMCACHED_NOTFOUND` if no `memcached_st`
115 instance was available, respectively.
118 If any method returns `MEMCACHED_IN_PROGRESS` then a lock on the pool could not
121 If any of the parameters passed to any of these functions is
122 invalid, `MEMCACHED_INVALID_ARGUMENTS` will be returned.
130 :manpage:`memcached(1)`
131 :manpage:`libmemcached(3)`
132 :manpage:`libmemcached_configuration(3)`
133 :manpage:`memcached_strerror(3)`
137 * :manpage:`memcached(1)`
138 * :doc:`../libmemcached`
139 * :doc:`../libmemcached/configuration`
140 * :doc:`../libmemcached/memcached_strerror`