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 initializedmemcached_ststruct ๐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 notMEMCACHED_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
expirationvalue isMEMCACHED_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
initialvalue to expire with the providedexpirationtime. 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
expirationvalue isMEMCACHED_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
initialvalue to expire with the providedexpirationtime. 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
- fedora 43: libmemcached-awesome-devel 1.1.4-7.fc43 ยท BSD-3-Clause
- fedora 43: libmemcached-awesome-devel 1.1.4-7.fc43 ยท BSD-3-Clause
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms