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