Skip to content

Instantly share code, notes, and snippets.

@stefpe
Last active September 4, 2018 12:39
Show Gist options
  • Save stefpe/3abc0e2693bdc9bb8317b4f6d935b315 to your computer and use it in GitHub Desktop.
Save stefpe/3abc0e2693bdc9bb8317b4f6d935b315 to your computer and use it in GitHub Desktop.
Test memcached modula distribution algorithm
<?php
const KEY = 'foo';
const VALUE = 'bar';
$memcached = new Memcached();
$memcached->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_MODULA);
$memcached->addServers([
['memcached1', 11211],
['memcached2', 11211]
]);
if ($memcached->getStats() === false) {
echo "memcached servers are offline" . PHP_EOL;
die();
}
$value = $memcached->get(KEY);
if ($value === false) {
$result = $memcached->set(KEY, VALUE);
} else {
echo "fetched key value pair" . PHP_EOL;
foreach ($memcached->getServerList() as $server) {
$client = new Memcached();
$client->addServer($server['host'], $server['port']);
printf("%s -> %s" . PHP_EOL, $server['host'], implode(',', $client->getAllKeys()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment