Merge pull request #140 from hussainnaqvee/patch-1
[awesomized/libmemcached] / libmemcachedutil / memcached_pool.rst
1 Working with memcached pools
2 ============================
3
4 SYNOPSIS
5 --------
6
7 #include <libmemcachedutil-|libmemcached_version|/pool.h>
8 Compile and link with -lmemcachedutil -lmemcached
9
10 .. type:: struct memcached_pool_st memcached_pool_st
11
12 .. function:: memcached_pool_st* memcached_pool(const char *option_string, size_t option_string_length)
13
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
17
18 .. function:: memcached_st* memcached_pool_destroy(memcached_pool_st* pool)
19
20 :param pool: initialized `memcached_pool_st` instance to free
21 :returns: pointer to the 'master' `memcached_st` instance by legacy
22
23 .. function:: memcached_st* memcached_pool_fetch(memcached_pool_st* pool, struct timespec* relative_time, memcached_return_t* rc)
24
25 .. versionadded:: 0.53
26 Synonym for memcached_pool_pop
27
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
32
33 .. function:: memcached_return_t memcached_pool_release(memcached_pool_st* pool, memcached_st* mmc)
34
35 .. versionadded:: 0.53
36 Synonym for memcached_pool_push.
37
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
41
42 .. function:: memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, memcached_behavior_t flag, uint64_t data)
43
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
48
49 .. function:: memcached_return_t memcached_pool_behavior_get(memcached_pool_st *pool, memcached_behavior_t flag, uint64_t *value)
50
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
55
56 .. function:: memcached_pool_st* memcached_pool_create(memcached_st* mmc, int initial, int max)
57
58 .. deprecated:: 0.46
59 Use `memcached_pool`
60
61 .. function:: memcached_st* memcached_pool_pop(memcached_pool_st* pool, bool block, memcached_return_t *rc)
62
63 .. deprecated:: 0.53
64 Use `memcached_pool_fetch`
65
66 .. function:: memcached_return_t memcached_pool_push(memcached_pool_st* pool, memcached_st *mmc)
67
68 .. deprecated:: 0.53
69 Use `memcached_pool_release`
70
71 DESCRIPTION
72 -----------
73
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.
78
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..
84
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.
89
90 `memcached_pool_release` is used to return a connection structure back to the
91 pool.
92
93 `memcached_pool_behavior_get` and `memcached_pool_behavior_set` is used to
94 get/set behavior flags on all connections in the pool.
95
96 Both `memcached_pool_release` and `memcached_pool_fetch` are thread safe.
97
98 RETURN VALUE
99 ------------
100
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
103 returns NULL.
104
105 `memcached_pool_pop` returns a pointer to a `memcached_st` structure from the
106 pool (or NULL if an allocation cannot be satisfied).
107
108 `memcached_pool_release` returns `MEMCACHED_SUCCESS` upon success.
109
110 `memcached_pool_behavior_get` and `memcached_pool_behavior_get` return
111 `MEMCACHED_SUCCESS` upon success.
112
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.
116
117 .. note::
118 If any method returns `MEMCACHED_IN_PROGRESS` then a lock on the pool could not
119 be obtained.
120
121 If any of the parameters passed to any of these functions is
122 invalid, `MEMCACHED_INVALID_ARGUMENTS` will be returned.
123
124
125 SEE ALSO
126 --------
127
128 .. only:: man
129
130 :manpage:`memcached(1)`
131 :manpage:`libmemcached(3)`
132 :manpage:`libmemcached_configuration(3)`
133 :manpage:`memcached_strerror(3)`
134
135 .. only:: html
136
137 * :manpage:`memcached(1)`
138 * :doc:`../libmemcached`
139 * :doc:`../libmemcached/configuration`
140 * :doc:`../libmemcached/memcached_strerror`