Last active
September 4, 2018 12:39
-
-
Save stefpe/3abc0e2693bdc9bb8317b4f6d935b315 to your computer and use it in GitHub Desktop.
Test memcached modula distribution algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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