Merge pull request #140 from hussainnaqvee/patch-1
[awesomized/libmemcached] / libmemcached / memcached_append.rst
1 Appending or Prepending Data
2 ============================
3
4 SYNOPSIS
5 --------
6
7 #include <libmemcached-|libmemcached_version|/memcached.h>
8 Compile and link with -lmemcached
9
10 .. function:: memcached_return_t memcached_prepend(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
11
12 .. function:: memcached_return_t memcached_append(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
13
14 .. function:: memcached_return_t memcached_prepend_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
15
16 .. function:: memcached_return_t memcached_append_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
17
18 :param ptr: pointer to an initialized `memcached_st` struct
19 :param group_key: key namespace
20 :param group_key_length: length of the key namespace without any terminating zero
21 :param key: the key
22 :param key_length: length of the key without any terminating zero
23 :param value: the value to append/prepend
24 :param value_length: the length of the value without any terminating zero
25 :param expiration: expiration as a unix timestamp or as relative expiration time in seconds
26 :param flags: 16 bit flags
27 :returns: `memcached_return_t` indicating success
28
29 DESCRIPTION
30 -----------
31
32 `memcached_prepend` and memcached_append are used to modify information on a
33 server. All methods take a ``key``, and ``key_length`` to store the object. Keys
34 are currently limited to 250 characters when using either a version of memcached
35 which is 1.4 or below, or when using the text protocol. You must supply both a
36 value and a length. Optionally you may set an expiration time for the object
37 and a 16 bit value (it is meant to be used as a bitmap). ``flags`` is a 4 byte
38 space that is stored along the main value. Many sub libraries make use of
39 this field, so in most cases users should avoid making use of it.
40
41 `memcached_prepend` places a segment of data before the last piece of data
42 stored. Currently expiration and key are not used in the server.
43
44 `memcached_append` places a segment of data at the end of the last piece of data
45 stored. Currently expiration and key are not used in the server.
46
47 `memcached_prepend_by_key` and `memcached_append_by_key` methods both behave in
48 a similar manner as the non key methods. The difference is that they use their
49 group_key parameter to map objects to particular servers.
50
51 If you are looking for performance, `memcached_set` with non-blocking IO is the
52 fastest way to store data on the server.
53
54 All of the above functions are tested with the `MEMCACHED_BEHAVIOR_USE_UDP`
55 behavior enabled. However, when using these operations with this behavior on,
56 there are limits to the size of the payload being sent to the server. The
57 reason for these limits is that the Memcached Server does not allow
58 multi-datagram requests and the current server implementation sets a datagram
59 size to 1400 bytes. Due to protocol overhead, the actual limit of the user
60 supplied data is less than 1400 bytes and depends on the protocol in use as,
61 well as the operation being executed. When running with the binary protocol,
62 `MEMCACHED_BEHAVIOR_BINARY_PROTOCOL`, the size of the key,value, flags and
63 expiry combined may not exceed 1368 bytes. When running with the ASCII protocol,
64 the exact limit fluctuates depending on which function is being executed and
65 whether the function is a cas operation or not. For non-cas ASCII set
66 operations, there are at least 1335 bytes available to split among the key,
67 key_prefix, and value; for cas ASCII operations there are at least 1318 bytes
68 available to split among the key, key_prefix and value. If the total size of the
69 command, including overhead, exceeds 1400 bytes, a `MEMCACHED_WRITE_FAILURE`
70 will be returned.
71
72 RETURN VALUE
73 ------------
74
75 All methods return a value of type `memcached_return_t`. On success the value
76 will be `MEMCACHED_SUCCESS`.
77
78 Use `memcached_strerror` to translate this value to a printable string.
79
80 SEE ALSO
81 --------
82
83 .. only:: man
84
85 :manpage:`memcached(1)`
86 :manpage:`libmemcached(3)`
87 :manpage:`memcached_strerror(3)`
88 :manpage:`memcached_set(3)`
89 :manpage:`memcached_add(3)`
90 :manpage:`memcached_cas(3)`
91 :manpage:`memcached_replace(3)`
92
93 .. only:: html
94
95 * :manpage:`memcached(1)`
96 * :doc:`../libmemcached`
97 * :doc:`memcached_set`
98 * :doc:`memcached_cas`
99 * :doc:`memcached_strerror`