MEMCACHED_POOL_BEHAVIOR_GET(3)

πŸ’– MEMCACHED_POOL_BEHAVIOR_GET πŸ’–

okay so bestie, this one lives in section 3 of the libmemcached-awesome manual, and its full glow-up name is MEMCACHED_P...BEHAVIOR_GET(3). It's all about the ✨connection pool✨ β€” the little clique of memcached_st objects you keep around so you don't have to keep making new friends. Let's get into it 🫢


🌸 NAME 🌸

memcached_pool_behavior_get β€” libmemcached Documentation


✨ SYNOPSIS ✨

#include <libmemcachedutil-1.0/pool.h>

Compile and link with -lmemcachedutil -lmemcached

typedef struct memcached_pool_st memcached_pool_st

πŸ¦‹ memcached_pool_st *memcached_pool(const char *option_string, size_t option_string_length)

Parameters

  • option_string β€” configuration string
  • option_string_length β€” length of options_string without any trailing zero byte

Returns

allocated and initialized memcached_pool_st instance on success or nullptr on failure

πŸ¦‹ memcached_st *memcached_pool_destroy(memcached_pool_st *pool)

Parameters

  • pool β€” initialized memcached_pool_st instance to free

Returns

pointer to the 'master' memcached_st instance by legacy

πŸ¦‹ memcached_st *memcached_pool_fetch(memcached_pool_st *pool, struct timespec *relative_time, memcached_return_t *rc)

Added in version 0.53 β€” it's a synonym for memcached_pool_pop πŸ’…

Parameters

  • pool β€” initialized memcached_pool_st instance
  • relative_time β€” time to block thread and wait for a connection to become available when pool size is exceeded, unless nullptr
  • rc β€” out pointer to memcached_return_t

Returns

pointer to an available memcached_st instance

πŸ¦‹ memcached_return_t memcached_pool_release(memcached_pool_st *pool, memcached_st *mmc)

Added in version 0.53 β€” synonym for memcached_pool_push ✨

Parameters

  • pool β€” initialized memcached_pool_st instance
  • mmc β€” the memcached_st instance to return to the pool

Returns

memcached_return_t indicating success

πŸ¦‹ memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, memcached_behavior_t flag, uint64_t data)

Parameters

  • pool β€” initialized memcached_pool_st instance
  • flag β€” the behavior to change
  • value β€” the value to set for flag

Returns

memcached_return_t indicating success

πŸ¦‹ memcached_return_t memcached_pool_behavior_get(memcached_pool_st *pool, memcached_behavior_t flag, uint64_t *value)

Parameters

  • pool β€” initialized memcached_pool_st instance
  • flag β€” the behavior to read
  • value β€” out pointer to receive the set value of flag

Returns

memcached_return_t indicating success

πŸ¦‹ memcached_pool_st *memcached_pool_create(memcached_st *mmc, int initial, int max)

Deprecated since version 0.46 β€” use memcached_pool() instead πŸ™ˆ

πŸ¦‹ memcached_st *memcached_pool_pop(memcached_pool_st *pool, bool block, memcached_return_t *rc)

Deprecated since version 0.53 β€” use memcached_pool_fetch() instead 😭

πŸ¦‹ memcached_return_t memcached_pool_push(memcached_pool_st *pool, memcached_st *mmc)

Deprecated since version 0.53 β€” use memcached_pool_release() instead πŸ’€

🌈 DESCRIPTION 🌈

memcached_pool() is the one that creates the connection pool, and the whole point is to skip the overhead of using memcached_clone for short lived memcached_st objects. For the deets on how the configuration string is formatted, go peek at libmemcached Configuration πŸ‘€

memcached_pool_destroy() destroys the connection pool that was created with memcached_pool_create() and releases all the allocated resources. It hands you back the pointer to the memcached_st structure that was passed as an argument to memcached_pool_create(), and it returns the ownership of that pointer to the caller when created with memcached_pool_create() β€” otherwise NULL is returned.. (yes, two dots, we don't make the rules πŸ’…)

memcached_pool_fetch() grabs a connection structure out of the connection pool. The relative_time argument is the vibe check for whether the function should block and wait for a connection structure to become available when you try to exceed the maximum size. Heads up: you need to specify time in relative time ⏳

memcached_pool_release() gives a connection structure back to the pool, like returning a borrowed hoodie πŸ§₯

memcached_pool_behavior_get() and memcached_pool_behavior_set() get/set behavior flags on all connections in the pool. All of them. Every single one. periodt.

Both memcached_pool_release() and memcached_pool_fetch() are thread safe πŸ‘‘


⭐ RETURN VALUE ⭐

memcached_pool_destroy() returns the pointer (and the ownership) to the memcached_st structure used to create the pool. And if connections are still in use? It returns NULL, no cap.

memcached_pool_pop() returns a pointer to a memcached_st structure from the pool (or NULL if an allocation cannot be satisfied).

memcached_pool_release() returns MEMCACHED_SUCCESS upon success πŸŽ€

memcached_pool_behavior_get() and memcached_pool_behavior_get() return MEMCACHED_SUCCESS upon success. (not me pointing out it says _get twice β€” that's literally what the page says, iykyk 😭)

memcached_pool_fetch() may return MEMCACHED_TIMEOUT if a timeout occurs while waiting for a free memcached_st instance, or MEMCACHED_NOTFOUND if no memcached_st instance was available, respectively.

NOTE: If any method returns MEMCACHED_IN_PROGRESS then a lock on the pool could not be obtained. 🚨 If any of the parameters passed to any of these functions is invalid, MEMCACHED_INVALID_ARGUMENTS will be returned.

πŸ‘‘ SEE ALSO πŸ‘‘

memcached(1) libmemcached(3) libmemcached_configuration(3) ‐ memcached_strerror(3)


and that's the whole page, bestie πŸ’œ this was libmemcached-awesome, version 1.1, dated Jul 24, 2025 β€” go forth and pool responsibly, you've got this fr fr πŸŒΈπŸ¦‹βœ¨

πŸ“¦ where this page comes from