< ?php //連接 $mem = new Memcache; $mem->connect("memcached_ip", memcached_port); //保存數據 $mem->set('用於存儲值的鍵名。', '存儲的值',’過期時間’); $val = $mem->get('用於存儲值的鍵名'); echo "Get 用於存儲值的鍵名 value: " . $val ."<br />"; //替換數據 $mem->replace('用於存儲值的鍵名', '存儲的值 ', 0, 60); $val = $mem->get('用於存儲值的鍵名'); echo "Get 用於存儲值的鍵名 value: " . $val . "<br />"; //保存數組 $arr = array('aaa', 'bbb', 'ccc', 'ddd'); $mem->set('key', $arr, 0, 60); $val2 = $mem->get('key'); echo "Get key value: "; print_r($val2); echo "<br />"; //刪除數據 $mem->delete('用於存儲值的鍵名'); $val = $mem->get('用於存儲值的鍵名'); echo "Get 用於存儲值的鍵名 value: " . $val . "<br />"; //清除所有數據 $mem->flush(); $val2 = $mem->get('key'); echo "Get key value: "; print_r($val2); echo "<br />"; //關閉連接 $mem->close(); ?>