dongshanjin8947 2014-04-27 10:59
浏览 10
已采纳

如何添加一个现有的密钥memcache php数据?

I have a large amount of data in memcache, and currently i am troubling with How can i update value on memcache?

I have set value with multi-dimention array..

and now i have two cases here:

  1. I want to add new value in Memcache in same key
  2. I want to update some value of one particular array.

I know i can do that by get -> modify -> set

$data=$m->get('foo');

$data[]=array('id'=>134,'title'=>'My First Car','content'=>'I love my car');

$m->set('foo',$data,TRUE,0);

In this example..user can change its title, content etc. so i need to update these information in memcache.

But getting data on every change which is more than 1MB, that will not be a good idea.

and I also learn about append but it says it only works for string values. that means i can not append Array to with existing key.

Is there any way to set/update data on existing key without getting data?

Please help..

  • 写回答

1条回答 默认 最新

  • dongyang4615 2014-04-27 11:04
    关注

    Just call $m->get the first time to populate $data, and don't call it again if you're just making updates:-

    if (!count($data))
        $data=$m->get('foo');
    
    $data[]=array('id'=>134,'title'=>'My First Car','content'=>'I love my car');
    
    $m->set('foo',$data,TRUE,0);
    

    If you make $data global then you can reference it from other functions

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置