Ejemplo n.º 1
0
 public function testSetGetValue()
 {
     $key = new Key();
     $this->assertNull($key->getValue());
     $key->setValue('veewee');
     $this->assertEquals('veewee', $key->getValue());
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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')));
 }
Ejemplo n.º 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;
 }