Esempio n. 1
0
 /**
  * @param string $host
  * @param int $port
  * @param int $timeout
  * @return Handler
  */
 public static function factory($host = '127.0.0.1', $port = 11211, $timeout = 1)
 {
     if (self::$handler === null) {
         self::$handler = new self();
         self::$handler->connect($host, $port, $timeout);
     }
     return self::$handler;
 }
Esempio n. 2
0
 public static function getInstance(array $memcachedPool = null)
 {
     if (self::$_INSTANCE === null) {
         if (is_null($memcachedPool) && !empty(INIT::$MEMCACHE_SERVERS)) {
             $memcachedPool = INIT::$MEMCACHE_SERVERS;
         } elseif (is_null($memcachedPool) && empty(INIT::$MEMCACHE_SERVERS)) {
             throw new LogicException('No Memcached server(s) configured.');
         }
         self::$_MemCachePool = $memcachedPool;
         self::$_INSTANCE = new self();
     }
     return self::$_INSTANCE;
 }
Esempio n. 3
0
 public function testZeroIncrement()
 {
     $serverPool = array('127.0.0.1:11211' => 1, 'localhost:11211' => 1);
     $x = MemcacheHandler::getInstance($serverPool);
     $this->assertEquals(0, $x->increment('x', 0));
     $this->assertEquals(1, $x->increment('x', 1));
     $this->assertEquals(0, $x->decrement('x', 2));
     $this->assertEquals(0, $x->decrement('x'));
     $this->assertEquals(0, $x->decrement('x'));
     $this->assertEquals(0, $x->decrement('x'));
 }