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