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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看