---
name: "memcached_stat"
section: "3"
platform: "linux"
package: "libmemcached-awesome"
version: "1.1.4-4"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/memcached_stat"
---

# memcached\_stat(3)

libmemcached Documentation Get memcached statistics

## NAME

memcached\_stat - libmemcached Documentation

Get memcached statistics

## SYNOPSIS

- **#include \<libmemcached/memcached.h\>**

  Compile and link with -lmemcached

- **typedef struct memcached\_stat\_st memcached\_stat\_st**

  - **typedef memcached\_return\_t \<#\_CPPv418memcached\_return\_t\> (\*memcached\_stat\_fn)(const memcached\_instance\_st \*server, const char \*key, size\_t key\_length, const char \*value, size\_t value\_length, void \*context)**

  - **Param server**

    pointer to the **memcached\_instance\_st** being stat'ed

  - **Param key**

    the current key

  - **Param key\_length**

    the length of the **key** without any terminating zero

  - **Param value**

    the value read

  - **Param value\_length**

    the length of the value without any terminating zero

  - **Param context**

    pointer to the user supplied context

  - **Returns**

    **memcached\_return\_t** \<#\_CPPv418memcached\_return\_t\> indicating success

- **memcached\_stat\_st \*memcached\_stat(memcached\_st \<#\_CPPv412memcached\_st\> \*ptr, char \*args, memcached\_return\_t \<#\_CPPv418memcached\_return\_t\> \*error)**

  - **Parameters**

    - •

      **ptr** -- pointer to an initialized **memcached\_st** \<#\_CPPv412memcached\_st\> struct

    - •

      **args** -- particular state object to query

    - •

      **error** -- pointer to **memcached\_return\_t** \<#\_CPPv418memcached\_return\_t\> indicating success

  - **Returns**

    array of **memcached\_stat\_st** objects for all available servers

- **memcached\_return\_t \<#\_CPPv418memcached\_return\_t\> memcached\_stat\_servername(memcached\_stat\_st \*stat, char \*args, const char \*hostname, in\_port\_t port)**

  - **Parameters**

    - •

      **stat** -- pointer to a **memcached\_stat\_st** struct to fill

    - •

      **args** -- particular state object to query

    - •

      **hostname** -- the hostname or IP address of the server to stat

    - •

      **port** -- the port of the server to stat

  - **Returns**

    **memcached\_return\_t** \<#\_CPPv418memcached\_return\_t\> indicating success

- **char \*memcached\_stat\_get\_value(memcached\_st \<#\_CPPv412memcached\_st\> \*ptr, memcached\_stat\_st \*stat, const char \*key, memcached\_return\_t \<#\_CPPv418memcached\_return\_t\> \*error)**

  - **Parameters**

    - •

      **ptr** -- pointer to initialized **memcached\_st** \<#\_CPPv412memcached\_st\> struct

    - •

      **stat** -- pointer to initialized **memcached\_stat\_st** struct

    - •

      **key** -- the statistic to query

    - •

      **error** -- pointer to **memcached\_return\_t** \<#\_CPPv418memcached\_return\_t\> indicating success

  - **Returns**

    string value of the statistic

- **char \*\*memcached\_stat\_get\_keys(memcached\_st \<#\_CPPv412memcached\_st\> \*ptr, memcached\_stat\_st \*stat, memcached\_return\_t \<#\_CPPv418memcached\_return\_t\> \*error)**

  - **Parameters**

    - •

      **ptr** -- pointer to initialized **memcached\_st** \<#\_CPPv412memcached\_st\> struct

    - •

      **stat** -- pointer to initialized **memcached\_stat\_st** struct

    - •

      **error** -- pointer to **memcached\_return\_t** \<#\_CPPv418memcached\_return\_t\> indicating success

  - **Returns**

    array of default keys probably available in the statistics

- **memcached\_return\_t \<#\_CPPv418memcached\_return\_t\> memcached\_stat\_execute(memcached\_st \<#\_CPPv412memcached\_st\> \*ptr, const char \*args, memcached\_stat\_fn func, void \*context)**

  - **Parameters**

    - •

      **ptr** -- pointer to initialized **memcached\_st** \<#\_CPPv412memcached\_st\> struct

    - •

      **args** -- particular state object to query

    - •

      **func** -- **memcached\_stat\_fn** callback

    - •

      **context** -- pointer to user supplied context

  - **Returns**

    **memcached\_return\_t** \<#\_CPPv418memcached\_return\_t\> indication success

## DESCRIPTION

**libmemcached** has the ability to query a **[memcached(1)](/memcached/1.md) \<https://linux.die.net/man/1/memcached\>** server (or collection of servers) for their current state. Queries to find state return a **memcached\_stat\_st** structure. You are responsible for freeing this structure. While it is possible to access the structure directly it is not advisable. **memcached\_stat\_get\_value()** has been provided to query the structure.

**memcached\_stat\_execute()** uses the servers found in **memcached\_stat\_st** and executes a "stat" command on each server. args is an optional argument that can be passed in to modify the behavior of "stats". You will need to supply a callback function that will be supplied each pair of values returned by the memcached server.

**memcached\_stat()** fetches an array of **memcached\_stat\_st** structures containing the state of all available memcached servers. The return value must be freed by the calling application. If called with the **MEMCACHED\_BEHAVIOR\_USE\_UDP** \<#\_CPPv4N20memcached\_behavior\_t26MEMCACHED\_BEHAVIOR\_USE\_UDPE\> behavior set, a NULL value is returned and the error parameter is set to **MEMCACHED\_NOT\_SUPPORTED** \<#\_CPPv4N18memcached\_return\_t23MEMCACHED\_NOT\_SUPPORTEDE\>.

**memcached\_stat\_servername()** can be used standalone without a **memcached\_st** \<#\_CPPv412memcached\_st\> to obtain the state of a particular server.  "args" is used to define a particular state object (a list of these are not provided for by either the **memcached\_stat\_get\_keys()** call nor are they defined in the memcached protocol). You must specify the hostname and port of the server you want to obtain information on.

**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.

**memcached\_stat\_get\_keys()** returns a list of keys that the server has state objects on. You are responsible for freeing this list.

A command line tool, **memstat**, is provided so that you do not have to write an application to do this.

## RETURN VALUE

Varies, see particular functions.

Any method returning a **memcached\_stat\_st** expects you to free the memory allocated for it.

## SEE ALSO

**[memcached(1)](/memcached/1.md) \<https://linux.die.net/man/1/memcached\>** **[libmemcached(3)](/libmemcached/3.md) \<https://linux.die.net/man/3/libmemcached\>** **[memcached\_strerror(3)](/memcached_strerror/3.md) \<https://linux.die.net/man/3/memcached\_strerror\>**
