我们在两个服务器上都有两个带Memcached的服务器。
第一个是所谓的memcachedSetter
,第二个是memcachedGetter
。
服务器memcachedSetter
通过php uniq keys
函数创建createUID
并将扩展搜索参数作为值(我们获取搜索航班参数并绕过提供商的SOAP服务器)
public function createUID() {
return md5(uniqid(rand(),1));
}
当用户选择一个返回的航班变体进行预订时,会出现第二个航点。
memcachedGetter
想要将所选航班变体加入请求必需品。这是Set and Get value memcachedGetterServer 代码示例的示例。
memcachedSetter 设置动作:
public function memcachedSetterSetAction() {
$cacheConfig = new \Zend\Config\Config...;
$content = new \stdClass();
$content->content = 'Some search criteria';
$cache = \Zend\Cache\StorageFactory::factory(...);
$cache->setItem('taskA9E3..89', $content);
$cache->setItem('requestFC20..60', $content);
$cache->setItem('taskD987..76', $content);
$cache->setItem('request72D4..4A', $content);
die;
}
memcachedSetter 获取动作:
public function memcachedSetterGetAction() {
echo "<br> 1. ";
$requestData = $cache->getItem('taskA9E3..89');
var_dump($requestData );
echo "<br> 2. ";
$requestData = $cache->getItem('requestFC20..60');
var_dump($requestData );
echo "<br> 3. ";
$requestData = $cache->getItem('taskD987..76');
var_dump($requestData );
echo "<br> 4. ";
$requestData = $cache->getItem('request72D4..4A');
var_dump($requestData );
}
这样我们设置并获取每个键/值。然后,当我们尝试通过第二台服务器上的键获取值时,会出现魔术:
memcachedGetter 获取动作:
public function memcachedSetterGetAction() {
echo "<br> 1. ";
$requestData = $cache->getItem('taskA9E3..89');
var_dump($requestData );
echo "<br> 2. ";
$requestData = $cache->getItem('requestFC20..60');
var_dump($requestData );
echo "<br> 3. ";
$requestData = $cache->getItem('taskD987..76');
var_dump($requestData );
echo "<br> 4. ";
$requestData = $cache->getItem('request72D4..4A');
var_dump($requestData );
}
memcached Getter 上的相同代码只返回一部分值即时全套设置为memcached Setter :
1. object(stdClass)#331 (1) { ["content"]=> string(17) "Some sea..." }
2. object(stdClass)#332 (1) { ["content"]=> string(17) "Some sea..." }
3. object(stdClass)#336 (1) { ["content"]=> string(17) "Some sea..." }
4. object(stdClass)#339 (1) { ["content"]=> string(17) "Some sea..." }
VS
1. object(stdClass)#335 (1) { ["content"]=> string(17) "Some sea..." }
2. object(stdClass)#331 (1) { ["content"]=> string(17) "Some sea..." }
3. NULL
4. NULL