使用MemcacheD v1.4.22
PECL MemcacheD library v2.2.0
PHP v5.3.19(cli)
我正在尝试将数组存储到缓存
中$array = $sql->get_arr ('SELECT properties FROM obj_properties WHERE obj_id="'.$id.'"');
var_dump($array); // output below
array(10) {
[0] => string(3) "976"
["parent"] => string(3) "976"
[1] => string(5) "Ziedi"
["name"] => string(5) "Ziedi"
[2] => string(0) ""
["int_name"] => string(0) ""
[3] => string(1) "1"
["type"] => string(1) "1"
[4] => string(1) "1"
["status"] => string(1) "1"
}
$memcached->set( $memKey, $ret_val, $max_time );
$returnArray = $memcached->get( $memKey );
var_dump($returnArray); // output below
object(stdClass)#5 (10) {
["0"] => string(3) "976"
["parent"] => string(3) "976"
["1"] => string(5) "Ziedi"
["name"] => string(5) "Ziedi"
["2"] => string(0) ""
["int_name"] => string(0) ""
["3"] => string(1) "1"
["type"] => string(1) "1"
["4"] => string(1) "1"
["status"] => string(1) "1"
}
我正在存储一个带有混合整数/字符串键的数组,这对于php应该不是问题,但显然它是用于memcached的?是否记录在任何地方?任何变通方法或提示?
如果我查看密钥的终端输出:
$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
get dev_id_1_04115ec378e476c56d19d827bcf8db56
VALUE dev_id_1_04115ec378e476c56d19d827bcf8db56 6 114
{"0":"976","parent":"976","1":"Ziedi","name":"Ziedi","2":"","int_name":"","3":"1","type":"1","4":"1","status":"1"}
我们看到数组实际上是保存为对象而不是数组意味着输出是正确的但是以某种方式存储将此数组转换为对象...
不幸的是我无法摆脱基于字符串或int的数组键元素,所以我不得不以某种方式处理它们。
任何帮助表示感谢。
答案 0 :(得分:4)
经过两天痛苦的研究后发现,memcached配置被设置为序列化为php.ini文件中的对象:
memcached.serializer = "json"
将其更改为
memcached.serializer = "json_array"
一如既往,感谢Stackoverflow - 即使它没有给你答案,它也会让你觉得更有建设性。