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 initialized memcached_st struct. 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 \0 stays home 🏠
  • 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. 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 expiration value is MEMCACHED_EXPIRATION_NOT_ADD, the operation will fail. like, it's over. no key, no add, no nada πŸ’€
  • 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. 🫢

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 expiration value is MEMCACHED_EXPIRATION_NOT_ADD, the operation will fail. respectfully, it's not happening πŸ’…
  • 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. 😌

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