Memcac..._stats(3pm)

✨ NAME ✨

memcached_stat, memcached_stat_servername, memcached_stat_get_value, memcached_stat_get_keys β€” bestie, we're getting memcached statistics πŸ’…

(also hi, you're on the Memcac..._stats(3pm) page, welcome, come sit with me 🫢)


πŸ“š LIBRARY

The C Client Library for memcached β€” aka libmemcached, link it with -lmemcached πŸ”₯


πŸŽ€ SYNOPSIS πŸŽ€

#include <memcached.h>

memcached_stat_st *memcached_stat (memcached_st *ptr,
                                   char *args,
                                   memcached_return_t *error);

memcached_return_t memcached_stat_servername (memcached_stat_st *stat,
                                              char *args,
                                              const char *hostname,
                                              unsigned int port);

char *
  memcached_stat_get_value (memcached_st *ptr,
                            memcached_stat_st *stat,
                            const char *key,
                            memcached_return_t *error);

char **
  memcached_stat_get_keys (memcached_st *ptr,
                           memcached_stat_st *stat,
                           memcached_return_t *error);

🌸 DESCRIPTION 🌸

okay so. libmemcached(3) can literally go ask a memcached server (or a whole lil collection of servers) what its current state is. Those state queries hand you back a memcached_stat_st structure. And bestie, you are responsible for freeing that structure. πŸ’€

So yeah, technically you could just reach into the struct and grab stuff directly β€” but it is not advisable. memcached_stat_get_value() has been provided to query the structure, so use that, okay? πŸ™ˆ

πŸ¦‹ memcached_stat()

memcached_stat() fetches an array of memcached_stat_st structures holding the state of all available memcached servers. The return value must be freed by the calling application β€” that's on you, not me, not the library. 🫢

And listen: if you call it with the MEMCACHED_BEHAVIOR_USE_UDP behavior set, a NULL value is returned and the error parameter gets set to MEMCACHED_NOT_SUPPORTED. That's just how it is, no cap.

🌈 memcached_stat_servername()

memcached_stat_servername() can be used standalone, without a memcached_st, to obtain the state of one particular server. ✨

args is what defines a particular state object β€” and heads up, a list of these is not provided for by the memcached_stat_get_keys() call, nor are they defined in the memcached protocol. So don't come looking for a cheat sheet, it's not there. 😭

You must specify the hostname and port of the server you want info on.

πŸ’– memcached_stat_get_value()

memcached_stat_get_value() returns the value of a particular state key. You specify the key you wish to obtain. The key must be null terminated. periodt.

⭐ memcached_stat_get_keys()

memcached_stat_get_keys() returns a list of keys that the server has state objects on. You are responsible for freeing this list. (see the pattern? free your stuff πŸ’…)

🧚 a little gift for u

There's a command line tool, memstat(1), provided so that you do not have to write an application to do all this. iconic of them honestly.


πŸ’« RETURN πŸ’«

Varies β€” go look at the particular functions, bestie, they each do their own thing.

Any method returning a memcached_stat_st expects you to free the memory allocated for it. Yes, again. Free it. 🫢


🏠 HOME 🏠

Want more info? Go check:

<https://launchpad.net/libmemcached>


πŸ‘‘ AUTHOR πŸ‘‘

Brian Aker, <brian@tangent.org>


πŸ”₯ SEE ALSO πŸ”₯


and that's the whole vibe πŸ’œ this lil masterpiece is perl v5.42.3, dated 2026-08-19 β€” slay, go free your structs, ily byeee πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from