# Memcache连接
$memcache = new Memcache;
$memcache->connect("127.0.0.1", 11211) or die ("Could not connect");
# Memcache版本
$version = $memcache->getVersion();
echo "Memcached Server version: " . $version . "
";
# Memcache保存数据
$memcache->set('key1', 'This is first value', 0, 60);
$val = $memcache->get('key1');
echo "Get key1 value: " . $val ."
";
# Memcache替换数据
$memcache->replace('key1', 'This is replace value', 0, 60);
$val = $memcache->get('key1');
echo "Get key1 value: " . $val . "
";
# Memcache保存数组
$arr = array('aaa', 'bbb', 'ccc', 'ddd');
$memcache->set('key2', $arr, 0, 60);
$val2 = $memcache->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "
";
# Memcache删除数据(当前)
$memcache->delete('key1');
$val = $memcache->get('key1');
echo "Get key1 value: " . $val . "
";
# Memcache清除数据(所有)
$memcache->flush();
$val2 = $memcache->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "
";
# Memcache关闭连接
$memcache->close();
?>