---
name: "memcached_fetch"
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_fetch"
---

# memcached\_fetch(3)

Retrieving data from the server

## NAME

memcached\_fetch - Retrieving data from the server

## SYNOPSIS

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

  Compile and link with -lmemcached

- **char \*memcached\_fetch(memcached\_st \<#\_CPPv412memcached\_st\> \*ptr, char \*key, size\_t \*key\_length, size\_t \*value\_length, uint32\_t \*flags, memcached\_return\_t \<#\_CPPv418memcached\_return\_t\> \*error)**

  Deprecated since version 0.50: Use **memcached\_fetch\_result()** \<#\_CPPv422memcached\_fetch\_resultP12memcached\_stP19memcached\_result\_stP18memcached\_return\_t\> instead.

## DESCRIPTION

**memcached\_fetch()** is used to fetch an individual value from the server. **memcached\_mget()** \<#\_CPPv414memcached\_mgetP12memcached\_stPPCKcPK6size\_t6size\_t\> must always be called before using this method. You must pass in a key and its length to fetch the object.

You must supply three pointer variables which will give you the state of the returned object:

- •

  A **uint32\_t** pointer to contain whatever flags you stored with the value,

- •

  a **size\_t** pointer which will be filled with size of of the object, and

- •

  a **memcached\_return\_t** \<#\_CPPv418memcached\_return\_t\> pointer to hold any error.

The object will be returned upon success and NULL will be returned on failure.

**MEMCACHED\_END** \<#\_CPPv4N18memcached\_return\_t13MEMCACHED\_ENDE\> is returned by the error value when all objects that have been found are returned. The final value upon **MEMCACHED\_END** \<#\_CPPv4N18memcached\_return\_t13MEMCACHED\_ENDE\> is a NULL pointer.

Values returned by **memcached\_fetch()** must be freed by the caller.

All of the above functions are not tested when the **MEMCACHED\_BEHAVIOR\_USE\_UDP** \<#\_CPPv4N20memcached\_behavior\_t26MEMCACHED\_BEHAVIOR\_USE\_UDPE\> has been set. Executing any of these functions with this behavior on will result in **MEMCACHED\_NOT\_SUPPORTED** \<#\_CPPv4N18memcached\_return\_t23MEMCACHED\_NOT\_SUPPORTEDE\> being returned, or for those functions which do not return a **memcached\_return\_t** \<#\_CPPv418memcached\_return\_t\>, the error function parameter will be set to **MEMCACHED\_NOT\_SUPPORTED** \<#\_CPPv4N18memcached\_return\_t23MEMCACHED\_NOT\_SUPPORTEDE\>.

## RETURN VALUE

**memcached\_fetch()** sets error to to **MEMCACHED\_END** \<#\_CPPv4N18memcached\_return\_t13MEMCACHED\_ENDE\> upon successful conclusion.

**MEMCACHED\_NOTFOUND** \<#\_CPPv4N18memcached\_return\_t18MEMCACHED\_NOTFOUNDE\> will be return if no keys at all were found.

**MEMCACHED\_KEY\_TOO\_BIG** \<#\_CPPv4N18memcached\_return\_t21MEMCACHED\_KEY\_TOO\_BIGE\> is set to error whenever **memcached\_fetch()** was used and the key was set larger then **MEMCACHED\_MAX\_KEY**, which was the largest key allowed for the original memcached ascii server.

## 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\>** **[memcached\_fetch\_result(3)](/memcached_fetch_result/3.md) \<https://linux.die.net/man/3/memcached\_fetch\_result\>**
