简体   繁体   English

PHP-从一个服务器到另一个服务器的内存缓存复制键/值

[英]PHP - memcached copy key/value from one server to another

I am curious is there a possibility in PHP to copy key/value from one memcached server directly to another using Memcached module? 我很好奇,PHP是否有可能使用Memcached模块将键/值从一台Memcached服务器直接复制到另一台? Is connections to 2 different servers at one time allowed at all? 一次允许连接到两台不同的服务器吗?

Thanks in advance! 提前致谢!

The following would allow you to connect to two different Memcached servers and set the same data on both: 以下内容可让您连接到两个不同的Memcached服务器,并在两个服务器上设置相同的数据:

//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. 取决于您的情况以及您要实现的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM