コード例 #1
0
 public function testSetGetCas()
 {
     $key = new Key();
     $this->assertNull($key->getCas());
     $key->setCas(19);
     $this->assertEquals(19, $key->getCas());
 }
コード例 #2
0
 public function testSetKeys()
 {
     $store = new KeyStore(array());
     $this->assertEquals(0, count($store->getKeys()));
     $expectedKeyOne = new Key();
     $expectedKeyOne->setKey('testKey');
     $expectedKeyOne->setValue('testValue');
     $expectedKeyTwo = new Key();
     $expectedKeyTwo->setKey('moreTestKey');
     $expectedKeyTwo->setValue('moreTestValue');
     $store->setKeys(array($expectedKeyOne, $expectedKeyTwo));
     $expected = array(0 => $expectedKeyOne, 1 => $expectedKeyTwo);
     $this->assertEquals($expected, $store->getKeys());
 }
コード例 #3
0
 public function testIncrementDecrementKey()
 {
     $client = new Client(array('c1' => array(array('name' => 'local1', 'host' => 'localhost', 'port' => 11200))), 'MemcachedManager\\Tests\\Fixtures\\MockMemcached');
     $client->addKey('c1', 'k-test', 12);
     $expected = new Key();
     $expected->setKey('k-test');
     $expected->setValue(12);
     $this->assertEquals($expected, $client->getKey('c1', Hash::encode('k-test')));
     $client->incrementKey('c1', Hash::encode('k-test'));
     $client->incrementKey('c1', Hash::encode('k-test'));
     $expected->setValue(14);
     $this->assertEquals($expected, $client->getKey('c1', Hash::encode('k-test')));
     $client->decrementKey('c1', Hash::encode('k-test'));
     $expected->setValue(13);
     $this->assertEquals($expected, $client->getKey('c1', Hash::encode('k-test')));
 }
コード例 #4
0
 /**
  * Proxy function for getting a key from the data source
  *
  * @param $clusterName
  * @param $key
  *
  * @return Key|null
  */
 public function getKey($clusterName, $key)
 {
     $decodedKey = Hash::decode($key);
     $cluster = $this->getCluster($clusterName);
     $client = $this->processNodes($this->getClient(), $cluster->getNodes());
     if ($value = $client->getKey($decodedKey)) {
         $object = new Key();
         $object->setKey($decodedKey);
         $object->setValue($value);
         return $object;
     }
     return null;
 }