Merge pull request #140 from hussainnaqvee/patch-1
[awesomized/libmemcached] / libmemcached / memcached_auto.rst
1 Incrementing and Decrementing Values
2 ====================================
3
4 SYNOPSIS
5 --------
6
7 #include <libmemcached/memcached.h>
8 Compile and link with -lmemcached
9
10 .. function:: memcached_return_t memcached_increment (memcached_st *ptr, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
11
12 .. function:: memcached_return_t memcached_decrement (memcached_st *ptr, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
13
14 .. function:: memcached_return_t memcached_increment_with_initial (memcached_st *ptr, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value)
15
16 .. function:: memcached_return_t memcached_decrement_with_initial (memcached_st *ptr, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value)
17
18 .. function:: memcached_return_t memcached_increment_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
19
20 .. function:: memcached_return_t memcached_decrement_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
21
22 .. function:: memcached_return_t memcached_increment_with_initial_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value)
23
24 .. function:: memcached_return_t memcached_decrement_with_initial_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value)
25
26 :param ptr: pointer to an initialized `memcached_st` struct
27 :param group_key: key namespace
28 :param group_key_length: length of the key namespace without any terminating zero
29 :param key: the key
30 :param key_length: length of the key without any terminating zero
31 :param offset: offset to increment/decrement
32 :param initial: initial value if `key` does not exist and `expiration` is not `MEMCACHED_EXPIRATION_NOT_ADD`
33 :param expiration: expiration as a unix timestamp or as relative expiration time in seconds
34 :param value: the resulting value after initialization/increment/decrement
35 :returns: `memcached_return_t` indicating success
36
37 DESCRIPTION
38 -----------
39
40 :manpage:`memcached(1)` servers have the ability to increment and decrement keys
41 (overflow and underflow are not detected). This gives you the ability to use
42 memcached to generate shared sequences of values.
43
44 `memcached_increment` takes a ``key`` and ``key_length`` and increments the
45 value by the ``offset`` passed to it. The value is then returned via the
46 uint32_t ``value`` pointer you pass to it.
47
48 `memcached_decrement` takes a ``key`` and ``key_length`` and decrements the
49 value by the ``offset`` passed to it. The value is then returned via the
50 uint32_t ``value`` pointer you pass to it.
51
52 `memcached_increment_with_initial` takes a ``key`` and ``key_length`` and
53 increments the value by the ``offset`` passed to it. If the object specified by
54 ``key`` does not exist, one of two things may happen: If the ``expiration``
55 value is :c:macro:`MEMCACHED_EXPIRATION_NOT_ADD`, the operation will fail. For
56 all other ``expiration`` values, the operation will succeed by seeding the value
57 for that key with a initial value to expire with the provided expiration time.
58 The ``flags`` will be set to zero. The value is then returned via the uint32_t
59 ``value`` pointer you pass to it. ``memcached_increment_with_initial`` is only
60 available when using the binary protocol.
61
62 `memcached_decrement_with_initial` takes a ``key`` and ``key_length`` and
63 decrements the value by the ``offset`` passed to it. If the object specified by
64 ``key`` does not exist, one of two things may happen: If the ``expiration``
65 value is :c:macro:`MEMCACHED_EXPIRATION_NOT_ADD`, the operation will fail. For
66 all other ``expiration`` values, the operation will succeed by seeding the value
67 for that key with a initial value to expire with the provided expiration time.
68 The ``flags`` will be set to zero. The value is then returned via the uint32_t
69 ``value`` pointer you pass to it. `memcached_decrement_with_initial` is only
70 available when using the binary protocol.
71
72 `memcached_increment_by_key`, `memcached_decrement_by_key`,
73 `memcached_increment_with_initial_by_key`, and
74 `memcached_decrement_with_initial_by_key` are master key equivalents of the
75 above.
76
77 RETURN VALUE
78 ------------
79
80 A value of type `memcached_return_t` is returned.
81 On success that value will be `MEMCACHED_SUCCESS`.
82 Use `memcached_strerror` to translate this value to a printable string.
83
84 SEE ALSO
85 --------
86
87 .. only:: man
88
89 :manpage:`memcached(1)`
90 :manpage:`libmemcached(3)`
91 :manpage:`memcached_strerror(3)`
92
93 .. only:: html
94
95 * :manpage:`memcached(1)`
96 * :doc:`../libmemcached`
97 * :doc:`memcached_strerror`