dongzhi5587 2013-03-26 12:41
浏览 23

PHP - 从一台服务器到另一台服务器的memcached复制密钥/值

I am curious is there a possibility in PHP to copy key/value from one memcached server directly to another using Memcached module? Is connections to 2 different servers at one time allowed at all?

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongyin5516 2013-03-26 12:50
    关注

    The following would allow you to connect to two different Memcached servers and set the same data on both:

    //Server A
    $memcacheA = new Memcache;
    $memcacheA->connect(216.239.51.99, 11211) or die ("Could not connect");
    
    //Server B
    $memcacheB = new Memcache;
    $memcacheB->connect(115.239.51.98, 11211) or die ("Could not connect");
    
    //Getting data from your database.
    $myVal = $customObj->getSomethingFromDB();
    
    //If data not stored on Server A
    if($memcacheA->get('var_key') === false){
        //Store it on Server A
        $memcacheA->set('var_key', $myVar, MEMCACHE_COMPRESSED, 50);
    }
    
    //If data not stored on Server B
    if($memcacheB->get('var_key') === false){
        //Store it on Server B
        $memcacheB->set('var_key', $myVar, MEMCACHE_COMPRESSED, 50);
    }
    

    Depending on your use case, this may or may not be a good solution. Depends on what your situation is and what you're attempting to achieve.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法