-
Memcached是一个*开源的,高性能,分布式内存对象缓存系统。
-
set/get类型
$memcached = new Memcache();
$memcached->connect(‘127.0.0.1‘,11211);
//存取数据库数据,计数器等等,接口数据等等
$res = [
[
‘id‘=>1,
‘name‘=>‘国内新闻‘,
‘create_time‘=>date(‘Y-m-d H:i:s‘),
],
[
‘id‘=>2,
‘name‘=>‘国际新闻‘,
‘create_time‘=>date(‘Y-m-d H:i:s‘),
],
[
‘id‘=>3,
‘name‘=>‘新闻快讯‘,
‘create_time‘=>date(‘Y-m-d H:i:s‘),
]
];
//设置key
$memcached->set(‘key‘, json_encode($res)); //设置一个变量到内存中,名称是key 值是test
//获取key
$json = $memcached->get(‘key‘);
print_r(json_decode($json,true));
- 删除所有key
$memcached = new Memcache();
$memcached->connect(‘127.0.0.1‘,11211);
//删除key
$memcached->delete(‘key‘);
//删除所有
$memcached->flush();
``
- 统计信息
connect(‘127.0.0.1‘,11211);
print_r($memcached->getStats());
···