driver = new \common_persistence_InMemoryKvDriver(); /* * Php file persistence * /*$this->largeValuePersistence = (new \common_persistence_PhpFileDriver())->connect('joystick', array( 'dir' => '/var/www/tao/package-tao/data/jeje/joystick/', \common_persistence_KeyValuePersistence::MAX_VALUE_SIZE => 100 )); */ /* * Redis persistence $this->driver = new \common_persistence_PhpRedisDriver(); $this->largeValuePersistence = $this->driver->connect('redis', [ 'host' => '127.0.0.1', 'port' => 6379 ]); */ /* * In memory persistence */ $this->largeValuePersistence = new \common_persistence_KeyValuePersistence( [ \common_persistence_KeyValuePersistence::MAX_VALUE_SIZE => 100 ], $this->driver ); } public function tearDown(): void { unset($this->largeValuePersistence); } protected function get100000bytesValue() { return str_repeat('a', 100000); } public function testSetGet() { $this->largeValuePersistence->set('test', 'fixture'); $this->assertEquals('fixture', $this->largeValuePersistence->get('test')); $this->assertTrue($this->largeValuePersistence->del('test')); } public function testSetGetLargeValue() { $bigValue = $this->get100000bytesValue(); $this->largeValuePersistence->set('test', $bigValue); $this->assertEquals($bigValue, $this->largeValuePersistence->get('test')); $this->assertTrue($this->largeValuePersistence->del('test')); } public function testDelExistsLarge() { $bigValue = $this->get100000bytesValue(); $this->assertFalse($this->largeValuePersistence->exists('test')); $this->largeValuePersistence->set('test', $bigValue); $this->assertTrue($this->largeValuePersistence->exists('test')); $this->assertEquals($bigValue, $this->largeValuePersistence->get('test')); $this->assertTrue($this->largeValuePersistence->del('test')); $this->assertFalse($this->largeValuePersistence->exists('test')); $this->assertEmpty($this->largeValuePersistence->get('test')); } public function testDelExists() { $this->assertFalse($this->largeValuePersistence->exists('test')); $this->largeValuePersistence->set('test', 'fixture'); $this->assertTrue($this->largeValuePersistence->exists('test')); $this->assertTrue($this->largeValuePersistence->del('test')); $this->assertFalse($this->largeValuePersistence->exists('test')); $this->assertEmpty($this->largeValuePersistence->get('test')); } public function testMapMapControl() { $this->largeValuePersistence = new \common_persistence_KeyValuePersistence( [ \common_persistence_KeyValuePersistence::MAX_VALUE_SIZE => 100, \common_persistence_KeyValuePersistence::MAP_IDENTIFIER => 'iamamap', \common_persistence_KeyValuePersistence::START_MAP_DELIMITER => 'mapbegin', \common_persistence_KeyValuePersistence::END_MAP_DELIMITER => 'mapend', ], $this->driver ); $this->testDelExistsLarge(); } public function testSetValueLengthEqualsMax() { $str = str_repeat('a', 100); $this->largeValuePersistence->set('equalsMax', $str); $this->assertEquals($str, $this->largeValuePersistence->get('equalsMax')); $this->assertTrue($this->largeValuePersistence->del('equalsMax')); } }