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