Created
November 15, 2018 15:15
-
-
Save ZiTAL/78ecf4e081759dd5e922a51a6b85a58e to your computer and use it in GitHub Desktop.
php: memcached clie get example
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 | |
// erabilera: | |
// php memcached-cli.php --host 127.0.0.1 --port 11211 --get 304b2b4e8c1639f858a6326d35aa88e4 | |
$params = getCliParams(); | |
$i = new Memcached(); | |
$i->addServer($params['host'], $params['port']); | |
$i->setOption(Memcached::OPT_BINARY_PROTOCOL, true); | |
if(isset($params['get'])) | |
{ | |
$value = $i->get($params['get']); | |
echo $value; | |
} | |
function getCliParams() | |
{ | |
global $argv; | |
$params = array_shift($argv); | |
$tmp = array(); | |
$i = 0; | |
foreach ($argv as $a) | |
{ | |
if($i%2==0) | |
$key = preg_replace("/^\-\-/", '', $a); | |
else | |
$tmp[$key] = $a; | |
$i++; | |
} | |
return $tmp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment