Last active
September 17, 2017 08:23
-
-
Save benr77/258e42642b4632d5a826 to your computer and use it in GitHub Desktop.
Memcached wrapper for persistent connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ChaletOps\BaseBundle\Utils; | |
/** | |
* Class MemcachedWrapper | |
*/ | |
class MemcachedWrapper extends \Memcached | |
{ | |
/** | |
* @param string $persistentId | |
*/ | |
public function __construct($persistentId) | |
{ | |
parent::__construct($persistentId); | |
} | |
/** | |
* Prevent adding of new servers as duplicates. We're persistent! | |
* | |
* @param array $servers | |
* | |
* @return bool | |
*/ | |
public function addServers(array $servers) | |
{ | |
if (0 == count($this->getServerList())) | |
{ | |
return parent::addServers($servers); | |
} | |
return false; | |
} | |
/** | |
* Prevent adding of new server as duplicate. We're persistent! | |
* | |
* @param string $host | |
* @param int $port | |
* @param int $weight | |
* | |
* @return bool | |
*/ | |
public function addServer($host, $port, $weight = 0) | |
{ | |
foreach ($this->getServerList() as $server) | |
{ | |
if ($server['host'] == $host && $server['port'] == $port) | |
{ | |
return false; | |
} | |
} | |
return parent::addServer($host, $port, $weight); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! Does the Memcached Cache Adapter in Symfony 3.3 change the approach on this?