Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Created November 15, 2018 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZiTAL/78ecf4e081759dd5e922a51a6b85a58e to your computer and use it in GitHub Desktop.
Save ZiTAL/78ecf4e081759dd5e922a51a6b85a58e to your computer and use it in GitHub Desktop.
php: memcached clie get example
<?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