MEMCACHED_DECREMENT(3)
π memcached_decrement β Incrementing and Decrementing Values π
okay bestie, welcome to memcached_decrement(3), brought to you by libmemcached-awesome. sit down, grab a boba, and let's talk about making numbers go up and also making them go down. it's giving very much "counter go brrr." π
β¨ 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. yes you have to actually initialize it first, no shortcuts babes πgroup_keyβ key namespace π«Άgroup_key_lengthβ length of the key namespace without any terminating zero. count it exactly, bestie, the zero is NOT invited to the party πkeyβ the key πkey_lengthβ length of the key without any terminating zero. same rule, the\0stays home πoffsetβ offset to increment/decrement ππinitialβ initial value if key does not exist andexpirationis notMEMCACHED_EXPIRATION_NOT_ADDexpirationβ 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. and likeβ¦ heads up bestie: overflow and underflow are not detected π the server is just not doing a vibe check on your math. this gives you the ability to use memcached to generate shared sequences of values. iconic behaviour honestly.
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. so it's giving β¨ bidirectional communication β¨.
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. the way that number just goes down?? obsessed.
memcached_increment_with_initial() takes a key and key_length and increments the value by the offset passed to it. and here's the plot twist π β 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. like, it's over. no key, no add, no nada π - for all other
expirationvalues, the operation will succeed by seeding the value for that key with ainitialvalue 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. π«Ά
memcached_increment_with_initial is only available when using the binary protocol. no binary protocol, no initial-value magic, periodt. π
memcached_decrement_with_initial() takes a key and key_length and decrements the value by the offset passed to it. same plot twist energy: 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. respectfully, it's not happening π - for all other
expirationvalues, the operation will succeed by seeding the value for that key with ainitialvalue 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. π
memcached_decrement_with_initial() is also only available when using the binary protocol. same rule, same drama. π₯
memcached_increment_by_key(), memcached_decrement_by_key(), memcached_increment_with_initial_by_key(), and memcached_decrement_with_initial_by_key() are the master key equivalents of the above. basically the main character versions with group_key and group_key_length added to the cast πβ¨
π 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. so if something looks weird, that's your translator bestie π«Ά
π SEE ALSO π
memcached(1) libmemcached(3) memcached_strerror(3)
and that's the whole page, bestie!! this was libmemcached-awesome, version 1.1, dated Jul 24, 2025 π slay responsibly, and remember: the counter only goes up if you tell it to. 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