Merge Trunk
[awesomized/libmemcached] / docs / memcached_get.rst
1 ===============================
2 Retrieving data from the server
3 ===============================
4
5 .. index:: object: memcached_st
6
7 --------
8 SYNOPSIS
9 --------
10
11
12 #include <libmemcached/memcached.h>
13
14 .. c:function:: memcached_result_st * memcached_fetch_result (memcached_st *ptr, memcached_result_st *result, memcached_return_t *error);
15
16 .. c:function:: char * memcached_get (memcached_st *ptr, const char *key, size_t key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error);
17
18 .. c:function:: memcached_return_t memcached_mget (memcached_st *ptr, const char * const *keys, const size_t *key_length, size_t number_of_keys);
19
20 .. c:function:: char * memcached_get_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error);
21
22 .. c:function:: memcached_return_t memcached_mget_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char * const *keys, const size_t *key_length, size_t number_of_keys);
23
24 .. c:function:: char * memcached_fetch (memcached_st *ptr, char *key, size_t *key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error);
25
26 .. c:function:: memcached_return_t memcached_fetch_execute (memcached_st *ptr, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks);
27
28 .. c:function:: memcached_return_t memcached_mget_execute (memcached_st *ptr, const char * const *keys, const size_t *key_length, size_t number_of_keys, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks);
29
30 .. c:function:: memcached_return_t memcached_mget_execute_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char * const *keys, const size_t *key_length, size_t number_of_keys, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks);
31
32 Compile and link with -lmemcached
33
34
35 -----------
36 DESCRIPTION
37 -----------
38
39
40 memcached_get() is used to fetch an individual value from the server. You
41 must pass in a key and its length to fetch the object. You must supply
42 three pointer variables which will give you the state of the returned
43 object. A uint32_t pointer to contain whatever flags you stored with the value,
44 a size_t pointer which will be filled with size of of the object, and a
45 memcached_return_t pointer to hold any error. The object will be returned
46 upon success and NULL will be returned on failure. Any object returned by
47 memcached_get() must be released by the caller application.
48
49 memcached_mget() is used to select multiple keys at once. For multiple key
50 operations it is always faster to use this function. This function always
51 works asynchronously. memcached_fetch() is then used to retrieve any keys
52 found. No error is given on keys that are not found. You must call either
53 memcached_fetch() or memcached_fetch_result() after a successful call to
54 memcached_mget(). You should continue to call these functions until they
55 return NULL (aka no more values). If you need to quit in the middle of a
56 memcached_get() call, execute a memcached_quit(). After you do this, you can
57 issue new queries against the server.
58
59 memcached_fetch() is used to fetch an individual value from the server.
60 memcached_mget() must always be called before using this method. You
61 must pass in a key and its length to fetch the object. You must supply
62 three pointer variables which will give you the state of the returned
63 object. A uint32_t pointer to contain whatever flags you stored with the value,
64 a size_t pointer which will be filled with size of of the object, and a
65 memcached_return_t pointer to hold any error. The object will be returned
66 upon success and NULL will be returned on failure. :c:type:`MEMCACHD_END` is
67 returned by the \*error value when all objects that have been found are
68 returned. The final value upon :c:type:`MEMCACHED_END` is null. Values
69 returned by memcached_fetch() must be freed by the caller. memcached_fetch()
70 will be DEPRECATED in the near future, memcached_fetch_result() should be
71 used instead.
72
73 memcached_fetch_result() is used to return a memcached_result_st(3) structure
74 from a memcached server. The result object is forward compatible with changes
75 to the server. For more information please refer to the memcached_result_st(3)
76 help. This function will dynamically allocate a result structure for you
77 if you do not pass one to the function.
78
79 memcached_fetch_execute() is a callback function for result sets. Instead
80 of returning the results to you for processing, it passes each of the
81 result sets to the list of functions you provide. It passes to the function
82 a memcached_st that can be cloned for use in the called function (it can not
83 be used directly). It also passes a result set which does not need to be freed.
84 Finally it passes a "context". This is just a pointer to a memory reference
85 you supply the calling function. Currently only one value is being passed
86 to each function call. In the future there will be an option to allow this
87 to be an array.
88
89 memcached_mget_execute() and memcached_mget_execute_by_key() is
90 similar to memcached_mget(), but it may trigger the supplied callbacks
91 with result sets while sending out the queries. If you try to perform
92 a really large multiget with memcached_mget() you may encounter a
93 deadlock in the OS kernel (it will fail to write data to the socket because
94 the input buffer is full). memcached_mget_execute() solves this
95 problem by processing some of the results before continuing sending
96 out requests. Please note that this function is only available in the
97 binary protocol.
98
99 memcached_get_by_key() and memcached_mget_by_key() behave in a similar nature
100 as memcached_get() and memcached_mget(). The difference is that they take
101 a master key that is used for determining which server an object was stored
102 if key partitioning was used for storage.
103
104 All of the above functions are not tested when the \ ``MEMCACHED_BEHAVIOR_USE_UDP``\
105 has been set. Executing any of these functions with this behavior on will result in
106 \ ``MEMCACHED_NOT_SUPPORTED``\ being returned, or for those functions which do not return
107 a \ ``memcached_return_t``\ , the error function parameter will be set to
108 \ ``MEMCACHED_NOT_SUPPORTED``\ .
109
110
111 ------
112 RETURN
113 ------
114
115
116 All objects returned must be freed by the calling application.
117 memcached_get() and memcached_fetch() will return NULL on error. You must
118 look at the value of error to determine what the actual error was.
119
120 :c:func:`memcached_fetch_execute()` return :c:type:`MEMCACHED_SUCCESS` if
121 all keys were successful. :c:type:`MEMCACHED_NOTFOUND` will be return if no
122 keys at all were found.
123
124 :c:func:`memcached_fetch()` and :c:func:`memcached_fetch_result()` set error
125 to :c:type:`MEMCACHED_END` upon successful conclusion.
126 :c:type:`MEMCACHED_NOTFOUND` will be return if no keys at all were found.
127
128 MEMCACHED_KEY_TOO_BIG is set to error whenever memcached_fetch() was used
129 and the key was set larger then MEMCACHED_MAX_KEY, which was the largest
130 key allowed for the original memcached ascii server.
131
132
133 ----
134 HOME
135 ----
136
137
138 To find out more information please check:
139 `http://libmemcached.org/ <http://libmemcached.org/>`_
140
141
142
143 --------
144 SEE ALSO
145 --------
146
147 :manpage:`memcached(1)` :manpage:`libmemcached(3)` :manpage:`memcached_strerror(3)`