pilsetnieks / key-value-api
简单的键值缓存API,用于抽象底层键值存储。
0.3.1
2016-09-15 00:00 UTC
Requires
- php: >= 5.3.0
This package is not auto-updated.
Last update: 2024-09-28 17:54:27 UTC
README
简单的键值缓存API,用于抽象底层键值存储。目前实现了APC和memcache。
使用示例
$KV = new kv(
array('Enabled' => false),
array('Enabled' => true, 'Servers' => $Servers)
);
// Object style
$KV['Value1'] = 'asdf';
echo $KV['Value1']; // Outputs "asdf"
echo '<hr />';
// Static class style
echo kv::get('Value1'); // Outputs "asdf";
echo '<hr />';
kv::set('Value1', 'qwerty');
echo kv::get('Value1'); // Outputs "qwerty";
echo '<hr />';
kv::clear_all();
echo kv::get('Value1'); // Outputs "";
echo '<hr />';
kv::set('TestNumber', 42);
echo $KV['TestNumber'];
echo '<hr />';
kv::inc('TestNumber', 2);
echo $KV['TestNumber'];
可以通过多种方式指定memcache服务器
$Servers = [
['localhost', 11211],
['127.0.0.1']
];
$Servers = ['localhost:11211', '127.0.0.1'];
$Servers = 'localhost11211;127.0.0.1';
$KV = new kv(
array('Enabled' => false),
array('Enabled' => true, 'Servers' => $Servers)
);