有可能吗?
$mc = new Memcached();
$mc->addServer("127.0.0.1", 11211);
$data = array(
'key_one' => array('something' => '0',
'something_else1' => 1,
'something_else2' => 2,
'something_else3' => 3,
),
'key_two' => array('something' => '0',
'something_else1' => 1,
'something_else2' => 2,
'something_else3' => 3,
)
);
$result = $mc->get("data['key_one']['something_else2']");
if($result) {
echo $result;
} else {
echo "No data on Cache. Please refresh page pressing F5";
$mc->set("data", $data,15) or die ("Failed to save data at Memcached server");
}
答案 0 :(得分:1)
您的set()
应该有效:
$mc->set('data', $data, 15);
到get()
:
$result = $mc->get('data');
$something = $result['key_one']['something_else2'];
//or PHP >= 5.4.0
$result = $mc->get('data')['key_one']['something_else2'];
答案 1 :(得分:0)
不,不行。 Memcached是一个Key-Value商店。因此,您可以检索由唯一键存储的数据。 将起作用的是:
$_temp_result = $mc->get('key_one');
$result = $_temp_result['something_else2']
假设数据存储在Memcached中,如$data
答案 2 :(得分:0)
嗯,但是如何设置多个,这可能是正确的?
$mc->set('data')['key_deeper_1'],$value, $expired_time);
or
$data = array('key_1' => array(
'key_deeper_1' => 'value',
'key_deeper_2' => 'value',
)
);
$mc->set('data',$value, $expired_time);
$mc-> get('data')['key_deeper_1'];