douqian1975 2013-11-18 15:22
浏览 205
已采纳

predis hmset嵌套数组的值

I am using predis php client. My code is like:

$ObjArray = get_object_vars ( $obj );     
$redis->hmset("post:4545",$objArray);

ObjArray is like: array( "id" => 1212, "name" => "test", "likes" => array(1,2,3), "comments" => array(0=>(1,2,3),1=>(1,2,3))

With this I get the error: redis ERR Protocol error: invalid bulk length

Can't we have array in value of redis hashe?

  • 写回答

3条回答 默认 最新

  • drd0833 2013-11-20 10:33
    关注

    Redis hashes are not multidimensional so field values can only be strings. The values in likes and comments in your $ObjArray variable are arrays which means they are not good, you should either serialize them (JSON or whichever serialization format you prefer) or store them into different and separate keys.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序