Modify a value

public function append(
  string $key,
  string $value,
): Awaitable<void>;


  • string $key - Name of the key to modify
  • string $value - String to append


The following example shows how to use the MCRouter::append function.


namespace Hack\UserDocumentation\API\Examples\MCRouter\MCrouter\Append;

function get_simple_mcrouter(): \MCRouter {
  $servers = Vector { \getenv('HHVM_TEST_MCROUTER') };
  $mc = \MCRouter::createSimple($servers);
  return $mc;

async function set_value(\MCRouter $mc, string $key,
                         string $value): Awaitable<void> {
  // can also pass optional int flags and int expiration time (in seconds)
  await $mc->set($key, $value);

async function append_to_value(\MCRouter $mc, string $key,
                                string $append_str): Awaitable<void> {
  await $mc->append($key, $append_str);

async function run(): Awaitable<void> {
  $mc = get_simple_mcrouter();
  $unique_key = \str_shuffle('ABCDEFGHIJKLMN');
  await set_value($mc, $unique_key, 'Hi');
  $val = await $mc->get($unique_key);
  try {
    await append_to_value($mc, $unique_key, 'Oh');
    $val = await $mc->get($unique_key);
  } catch (\MCRouterException $ex) {

string(2) "Hi"
string(4) "HiOh"