MEMCACHED_AUTO(3)

๐Ÿ’– memcached_auto โ€” incrementing and decrementing values ๐Ÿ’–

okay bestie, welcome to memcached_auto(3) from libmemcached-awesome โœจ this is the page that teaches you how to make counters go up and down in memcached, and honestly? it's giving main character energy.


๐ŸŽ€ NAME ๐ŸŽ€

memcached_auto โ€” incrementing and decrementing values ๐Ÿฆ‹


โœจ SYNOPSIS โœจ

#include <libmemcached/memcached.h>
       Compile and link with -lmemcached

memcached_return_t memcached_increment(memcached_st *ptr, const char
*key, size_t key_length, uint32_t offset, uint64_t *value)

memcached_return_t memcached_decrement(memcached_st *ptr, const char
*key, size_t key_length, uint32_t offset, uint64_t *value)

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)

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)

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)

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)

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)

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)

๐ŸŒธ Parameters ๐ŸŒธ

  • ptr โ€” pointer to an initialized memcached_st struct ๐Ÿ’…
  • group_key โ€” key namespace ๐Ÿ—‚๏ธ
  • group_key_length โ€” length of the key namespace without any terminating zero ๐Ÿงฎ
  • key โ€” the key ๐Ÿ”‘
  • key_length โ€” length of the key without any terminating zero ๐Ÿงฎ
  • offset โ€” offset to increment/decrement โž•โž–
  • initial โ€” initial value if key does not exist and expiration is not MEMCACHED_EXPIRATION_NOT_ADD ๐ŸŒฑ
  • expiration โ€” expiration as a unix timestamp or as relative expiration time in seconds โณ
  • value โ€” the resulting value after initialization/increment/decrement ๐Ÿ†

๐Ÿ’ซ Returns ๐Ÿ’ซ

memcached_return_t indicating success โœ…


๐Ÿ”ฅ DESCRIPTION ๐Ÿ”ฅ

memcached(1) servers have the ability to increment and decrement keys (overflow and underflow are not detected). ๐Ÿ˜ณ this gives you the ability to use memcached to generate shared sequences of values. no cap, that's the whole point.

โš ๏ธ overflow and underflow are not detected โ€” the manpage says it, so i'm saying it, don't come for me ๐Ÿ’€

memcached_increment() takes a key and key_length and increments the value by the offset passed to it. the value is then returned via the uint32_t value pointer you pass to it. ๐ŸŽ€

memcached_decrement() takes a key and key_length and decrements the value by the offset passed to it. the value is then returned via the uint32_t value pointer you pass to it. ๐ŸŽ€

memcached_increment_with_initial() takes a key and key_length and increments the value by the offset passed to it. but here's the tea ๐Ÿต โ€” if the object specified by key does not exist, one of two things may happen:

  • if the expiration value is MEMCACHED_EXPIRATION_NOT_ADD, the operation will fail ๐Ÿ’€
  • for all other expiration values, the operation will succeed by seeding the value for that key with a initial value to expire with the provided expiration time. the flags will be set to zero. ๐ŸŒฑ

the value is then returned via the uint32_t value pointer you pass to it. and psst โ€” memcached_increment_with_initial is only available when using the binary protocol. ๐Ÿงš

memcached_decrement_with_initial() takes a key and key_length and decrements the value by the offset passed to it. if the object specified by key does not exist, one of two things may happen:

  • if the expiration value is MEMCACHED_EXPIRATION_NOT_ADD, the operation will fail ๐Ÿ’€
  • for all other expiration values, the operation will succeed by seeding the value for that key with a initial value to expire with the provided expiration time. the flags will be set to zero. ๐ŸŒฑ

the value is then returned via the uint32_t value pointer you pass to it. also memcached_decrement_with_initial() is only available when using the binary protocol. ๐Ÿงš

memcached_increment_by_key(), memcached_decrement_by_key(), memcached_increment_with_initial_by_key(), and memcached_decrement_with_initial_by_key() are master key equivalents of the above. ๐Ÿ‘‘


๐Ÿ‘‘ RETURN VALUE ๐Ÿ‘‘

a value of type memcached_return_t is returned. on success that value will be MEMCACHED_SUCCESS. use memcached_strerror() to translate this value to a printable string. ๐Ÿซถ


๐ŸŒˆ SEE ALSO ๐ŸŒˆ

memcached(1) libmemcached(3) memcached_strerror(3)


and that's the whole page bestie, you ate ๐Ÿ’… this was libmemcached-awesome version 1.1, dated Jul 24, 2025 โ€” iconic, no notes, periodt. ๐ŸŽ€โœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from