Merge pull request #140 from hussainnaqvee/patch-1
[awesomized/libmemcached] / libmemcached / memcached_cas.rst
1 Working with data on the server in an atomic fashion
2 ====================================================
3
4 SYNOPSIS
5 --------
6
7 #include <libmemcached/memcached.h>
8 Compile and link with -lmemcached
9
10 .. function:: memcached_return_t memcached_cas(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags, uint64_t cas)
11
12 .. function:: memcached_return_t memcached_cas_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, uint64_t cas)
13
14 :param ptr: pointer to an initialized `memcached_st` struct
15 :param group_key: key namespace
16 :param group_key_length: length of the `group_key` without any trailing zero
17 :param key: the key to check
18 :param key_length: the length of the `key` without any trailing zero
19 :param value: the value to set
20 :param value_length: the length of the `value` without any trailing zero
21 :param expiration: expiration time as unix timestamp or relative time in seconds
22 :param flags: 16 bit flags
23 :param cas: the ``cas`` value to compare
24 :returns: `memcached_return_t` indicating success
25
26 DESCRIPTION
27 -----------
28
29 `memcached_cas` overwrites data in the server as long as the ``cas`` value is
30 still the same in the server. You can get the ``cas`` value of a result by
31 calling `memcached_result_cas` on a `memcached_result_st` structure.
32
33 `memcached_cas_by_key` method behaves in a similar way as the non key methods.
34 The difference is that it uses the ``group_key`` parameter to map objects to
35 particular servers.
36
37 `memcached_cas` is tested with the `MEMCACHED_BEHAVIOR_USE_UDP` behavior
38 enabled. However, when using these operations with this behavior on, there are
39 limits to the size of the payload being sent to the server. The reason for
40 these limits is that the Memcached Server does not allow multi-datagram requests
41 and the current server implementation sets a datagram size to 1400 bytes. Due to
42 protocol overhead, the actual limit of the user supplied data is less than 1400
43 bytes and depends on the protocol in use as, well as the operation being
44 executed. When running with the binary protocol,
45 `MEMCACHED_BEHAVIOR_BINARY_PROTOCOL`, the size of the key,value, flags and
46 expiry combined may not exceed 1368 bytes. When running with the ASCII protocol,
47 the exact limit fluctuates depending on which function is being executed and
48 whether the function is a cas operation or not. For non-cas ASCII set
49 operations, there are at least 1335 bytes available to split among the key,
50 key_prefix, and value; for cas ASCII operations there are at least 1318 bytes
51 available to split among the key, key_prefix and value. If the total size of the
52 command, including overhead, exceeds 1400 bytes, a `MEMCACHED_WRITE_FAILURE`
53 will be returned.
54
55 RETURN VALUE
56 ------------
57
58 All methods return a value of type `memcached_return_t`.
59 On success the value will be `MEMCACHED_SUCCESS`.
60 Use `memcached_strerror` to translate this value to a printable
61 string.
62
63 SEE ALSO
64 --------
65
66 .. only:: man
67
68 :manpage:`memcached(1)`
69 :manpage:`libmemcached(3)`
70 :manpage:`memcached_strerror(3)`
71 :manpage:`memcached_set(3)`
72 :manpage:`memcached_append(3)`
73 :manpage:`memcached_add(3)`
74 :manpage:`memcached_prepend(3)`
75 :manpage:`memcached_replace(3)`
76
77 .. only:: html
78
79 * :manpage:`memcached(1)`
80 * :doc:`../libmemcached`
81 * :doc:`memcached_set`
82 * :doc:`memcached_append`
83 * :doc:`memcached_strerror`