Skip to content

memcache测试脚本

转载本站文章请注明:
转载来至:[记录与PHP的PK经历]
本文链接: memcache测试脚本

<?php
//连接
$mem = new Memcache;
$mem->connect(127.0.0.1, 11211);

//保存数据
$mem->set(key1, This is first value, 0, 60);
$val = $mem->get(key1);
echo Get key1 value: . $val .<br>;

//替换数据
$mem->replace(key1, This is replace value, 0, 60);
$val = $mem->get(key1);
echo Get key1 value: . $val . <br>;

//保存数组
$arr = array(aaa, bbb, ccc, ddd);
$mem->set(key2, $arr, 0, 60);
$val2 = $mem->get(key2);
echo Get key2 value: ;
print_r($val2);
echo <br>;

//删除数据
$mem->delete(key1);
$val = $mem->get(key1);
echo Get key1 value: . $val . <br>;

//清除所有数据
$mem->flush();
$val2 = $mem->get(key2);
echo Get key2 value: ;
print_r($val2);
echo <br>;

//关闭连接
$mem->close();
?>

如果正常的话,浏览器将输出:
Get key1 value: This is first value
Get key1 value: This is replace value
Get key2 value: Array ( [0] => aaa [1] => bbb [2] => ccc [3] => ddd )
Get key1 value:
Get key2 value:

memcache 测试(3)memcached php 测试脚本(1)memcache测试(1)

中文关键字:php pr 数据 脚本 浏览器 memcache 测试 value key1 get mem val echo key2 replace

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*
Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).