1MEMCACHED_CAS(3) libmemcached-awesome MEMCACHED_CAS(3)
2
3
4
6 memcached_cas - Atomic Compare and Swap
7
9 #include <libmemcached/memcached.h>
10 Compile and link with -lmemcached
11
12 memcached_return_t memcached_cas(memcached_st *ptr, const char *key,
13 size_t key_length, const char *value, size_t value_length, time_t expi‐
14 ration, uint32_t flags, uint64_t cas)
15
16 memcached_return_t memcached_cas_by_key(memcached_st *ptr, const char
17 *group_key, size_t group_key_length, const char *key, size_t
18 key_length, const char *value, size_t value_length, time_t expiration,
19 uint32_t flags, uint64_t cas)
20
21 Parameters
22
23 • ptr -- pointer to an initialized memcached_st struct
24
25 • group_key -- key namespace
26
27 • group_key_length -- length of the group_key without any
28 trailing zero
29
30 • key -- the key to check
31
32 • key_length -- the length of the key without any trail‐
33 ing zero
34
35 • value -- the value to set
36
37 • value_length -- the length of the value without any
38 trailing zero
39
40 • expiration -- expiration time as unix timestamp or rel‐
41 ative time in seconds
42
43 • flags -- 16 bit flags
44
45 • cas -- the cas value to compare
46
47 Returns
48 memcached_return_t indicating success
49
51 memcached_cas() overwrites data in the server as long as the cas value
52 is still the same in the server. You can get the cas value of a result
53 by calling memcached_result_cas() on a memcached_result_st structure.
54
55 memcached_cas_by_key() method behaves in a similar way as the non key
56 methods. The difference is that it uses the group_key parameter to map
57 objects to particular servers.
58
59 memcached_cas() is tested with the MEMCACHED_BEHAVIOR_USE_UDP behavior
60 enabled. However, when using these operations with this behavior on,
61 there are limits to the size of the payload being sent to the server.
62 The reason for these limits is that the Memcached Server does not allow
63 multi-datagram requests and the current server implementation sets a
64 datagram size to 1400 bytes. Due to protocol overhead, the actual limit
65 of the user supplied data is less than 1400 bytes and depends on the
66 protocol in use as, well as the operation being executed. When running
67 with the binary protocol, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, the size
68 of the key,value, flags and expiry combined may not exceed 1368 bytes.
69 When running with the ASCII protocol, the exact limit fluctuates de‐
70 pending on which function is being executed and whether the function is
71 a cas operation or not. For non-cas ASCII set operations, there are at
72 least 1335 bytes available to split among the key, key_prefix, and
73 value; for cas ASCII operations there are at least 1318 bytes available
74 to split among the key, key_prefix and value. If the total size of the
75 command, including overhead, exceeds 1400 bytes, a
76 MEMCACHED_WRITE_FAILURE will be returned.
77
79 All methods return a value of type memcached_return_t. On success the
80 value will be MEMCACHED_SUCCESS. Use memcached_strerror() to translate
81 this value to a printable string.
82
84 memcached(1) libmemcached(3) memcached_strerror(3) memcached_set(3)
85 memcached_append(3) memcached_add(3) memcached_prepend(3) memcached_re‐
86 place(3)
87
88
89
90
911.1 Nov 09, 2022 MEMCACHED_CAS(3)