PHP Memcached 存储数组,检索对象。错误?
PHP Memcached stores array, retrieves object. A bug?
使用 MemcacheD v1.4.22
PECL MemcacheD 库 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"
}
我正在存储一个包含混合 integer/string 键的数组,这对 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 的数组键元素,因此我将不得不以某种方式处理它们。
感谢任何帮助。
经过两天的痛苦研究后发现,memcached 配置被设置为序列化到 php.ini 文件中的对象:
memcached.serializer = "json"
改为
memcached.serializer = "json_array"
一如既往,感谢 Whosebug - 即使它没有给你答案,它会让你的想法更有建设性。
使用 MemcacheD v1.4.22
PECL MemcacheD 库 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"
}
我正在存储一个包含混合 integer/string 键的数组,这对 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 的数组键元素,因此我将不得不以某种方式处理它们。
感谢任何帮助。
经过两天的痛苦研究后发现,memcached 配置被设置为序列化到 php.ini 文件中的对象:
memcached.serializer = "json"
改为
memcached.serializer = "json_array"
一如既往,感谢 Whosebug - 即使它没有给你答案,它会让你的想法更有建设性。