Memcac...ed_auto(3pm)
β¨ NAME β¨
okay bestie, welcome to the counter headquarters π
this page β which lives in the 3pm slot of the User Contributed Perl Documentation, underneath the whole C Client Library for memcached situation β is all about four little functions that do one extremely specific thing:
memcached_incrementmemcached_decrementmemcached_increment_with_initialmemcached_decrement_with_initial
and the thing they do is: Manipulate counters. that's it. that's the job. no notes. π
πΈ LIBRARY πΈ
this is the C Client Library for memcached, aka libmemcached, and you link it with -lmemcached. iconic behavior honestly π«Ά
β¨ SYNOPSIS β¨
first things first, you gotta invite the header to the party:
#include <memcached.h>
and now, the full cast β all eight of them, not a single one skipped, because we don't do that here π:
memcached_return_t
memcached_increment (memcached_st *ptr,
const char *key, size_t key_length,
unsigned int offset,
uint64_t *value);
memcached_return_t
memcached_decrement (memcached_st *ptr,
const char *key, size_t key_length,
unsigned int 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 *master_key, size_t master_key_length,
const char *key, size_t key_length,
unsigned int offset,
uint64_t *value);
memcached_return_t
memcached_decrement_by_key (memcached_st *ptr,
const char *master_key, size_t master_key_length,
const char *key, size_t key_length,
unsigned int offset,
uint64_t *value);
memcached_return_t
memcached_increment_with_initial_by_key (memcached_st *ptr,
const char *master_key,
size_t master_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 *master_key,
size_t master_key_length,
const char *key,
size_t key_length,
uint64_t offset,
uint64_t initial,
time_t expiration,
uint64_t *value);
look at that lineup. main character energy from every single one of them π
π DESCRIPTION π
so like. memcached(1) servers can increment and decrement keys β that's the whole vibe. and before you ask, no: overflow and underflow are β¨notβ¨ detected. the server is not your mom, it will not catch you. π
but that's also the slay of it, because it means you can use memcached to generate shared sequences of values. a lil collab counter. very cute. very useful. periodt. π
π¦ the increment / decrement duo π¦
memcached_increment()β takes akeyand akeylength, and bumps the value up by whateveroffsetyou hand it. then the new value gets handed right back to you through thatunsigned int valuepointer you passed in. πmemcached_decrement()β takes akeyand akeylength, and drops the value down by theoffsetyou handed it. then the value comes back through that sameunsigned int valuepointer you passed in. πΈ
π the "_with_initial" girlies π
these two are the same deal but they also handle the "what if she doesn't exist yet" moment, and honestly? that's the whole plot twist:
memcached_increment_with_initial()β takes akeyandkeylength, and increments the value by theoffsetyou passed it. BUT β and this is the important part β if the object specified bykeydoes not exist, one of two things may happen:- If the
expirationvalue isMEMCACHED_EXPIRATION_NOT_ADD, the operation will fail. sorry bestie π - For all other
expirationvalues, the operation will succeed by seeding the value for that key with aninitialvalue, set to expire with the providedexpirationtime. and heads up: the flags will be set to zero.
- If the
The value is then returned via the unsigned int value pointer you pass to it. β¨
memcached_decrement_with_initial()β takes akeyandkeylength, and decrements the value by theoffsetyou passed it. same energy for the missing-key situation β if the object specified bykeydoes not exist, one of two things may happen:- If the
expirationvalue isMEMCACHED_EXPIRATION_NOT_ADD, the operation will fail. π« - For all other
expirationvalues, the operation will succeed by seeding the value for that key with aninitialvalue, set to expire with the providedexpirationtime. flags get set to zero, no cap.
- If the
The value is then returned via the unsigned int value pointer you pass to it. π
π the master-key equivalents π
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 all of the above. yes, that means they take a master_key and a master_key_length on top of everything else β they're the extra ones, and they ate. π₯
β RETURN β
you get back a value of type memcached_return_t. on success that value will be MEMCACHED_SUCCESS π
and if you ever need to turn that number into a readable string, hit up memcached_strerror() β she translates. iykyk. π
π HOME π
want more lore? the full source of truth lives here:
<https://launchpad.net/libmemcached>
go, read, obsess. π§
πΈ AUTHOR πΈ
this whole thing was authored by Brian Aker, <brian@tangent.org>. thank you for your service king π
π¦ SEE ALSO π¦
the extended universe, all linked up:
and that's the tea, bestie π this lil tour was brought to you by perl v5.42.3, dated 2026-08-19, riding in under the Memcac...ed_auto(3pm) banner. stay incrementing, stay slaying, and remember: you're the main character of your own counter π
β¨π
π¦ where this page comes from
- ubuntu stonking: libmemcached-libmemcached-perl 1.001801+dfsg-6build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms