PHP Memcached存储数组,检索对象。有毛病吗

Did*_*zis 1 php arrays memcached object

使用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"
}
Run Code Online (Sandbox Code Playgroud)

我用混合整数/字符串键存储数组,这对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"}
Run Code Online (Sandbox Code Playgroud)

我们看到数组实际上是保存为对象而不是数组,这意味着输出是正确的,但是以某种方式存储会将其转换为对象...

不幸的是,我无法摆脱基于字符串或整数的数组键元素,因此我将不得不以某种方式处理它们。

任何帮助表示赞赏。

Did*_*zis 5

经过两天的艰苦研究,结果表明,将memcached配置设置为序列化为php.ini文件中的对象:

memcached.serializer = "json"
Run Code Online (Sandbox Code Playgroud)

改成

memcached.serializer = "json_array"
Run Code Online (Sandbox Code Playgroud)

与往常一样,感谢Stackoverflow-即使它没有给您答案,它也使您认为更具建设性。