_instance = new Cm_Cache_Backend_Redis(array( 'server' => getenv('REDIS_SERVER') ?: 'localhost', 'port' => getenv('REDIS_PORT') ?: '6379', 'database' => '1', 'notMatchingTags' => true, 'force_standalone' => $this->forceStandalone, 'compress_threshold' => 100, 'compression_lib' => 'gzip', 'use_lua' => true, 'lua_max_c_stack' => self::LUA_MAX_C_STACK, 'auto_expire_lifetime' => $this->autoExpireLifetime, 'auto_expire_refresh_on_load' => $this->autoExpireRefreshOnLoad, )); $this->_instance->clean(); $this->_instance->___scriptFlush(); parent::setUp($noTag); } public function tearDown(): void { parent::tearDown(); unset($this->_instance); } public function testGetWithAnExpiredCacheId(): void { $this->markTestSkipped('Getting expired data is unsupported by Redis'); } public function testCompression(): void { $longString = str_repeat(md5('asd')."\r\n", 50); $this->assertTrue($this->_instance->save($longString, 'long', array('long'))); $this->assertTrue($this->_instance->load('long') == $longString); } public function testExpiredCleanup(): void { $this->assertTrue($this->_instance->clean()); $this->assertTrue($this->_instance->save('BLAH', 'foo', array('TAG1', 'TAG2'), 1)); $this->assertTrue($this->_instance->save('BLAH', 'bar', array('TAG1', 'TAG3'), 1)); $ids = $this->_instance->getIdsMatchingAnyTags(array('TAG1','TAG2','TAG3')); sort($ids); $this->assertEquals(array('bar','foo'), $ids); // sleep(2); $this->_instance->___expire('foo'); $this->_instance->___expire('bar'); $this->_instance->clean(Zend_Cache::CLEANING_MODE_OLD); $this->assertEquals(array(), $this->_instance->getIdsMatchingAnyTags(array('TAG1','TAG2','TAG3'))); $this->assertEquals(array(), $this->_instance->getTags()); } /** $this->_instance->save('bar : data to cache', 'bar', array('tag3', 'tag4')); $this->_instance->save('bar2 : data to cache', 'bar2', array('tag3', 'tag1')); $this->_instance->save('bar3 : data to cache', 'bar3', array('tag2', 'tag3')); */ public function testGetIdsMatchingAnyTags(): void { $res = $this->_instance->getIdsMatchingAnyTags(array('tag999')); $this->assertCount(0, $res); } public function testGetIdsMatchingAnyTags2(): void { $res = $this->_instance->getIdsMatchingAnyTags(array('tag1', 'tag999')); $this->assertCount(1, $res); $this->assertTrue(in_array('bar2', $res)); } public function testGetIdsMatchingAnyTags3(): void { $res = $this->_instance->getIdsMatchingAnyTags(array('tag3', 'tag999')); $this->assertCount(3, $res); $this->assertTrue(in_array('bar', $res)); $this->assertTrue(in_array('bar2', $res)); $this->assertTrue(in_array('bar3', $res)); } public function testGetIdsMatchingAnyTags4(): void { $res = $this->_instance->getIdsMatchingAnyTags(array('tag1', 'tag4')); $this->assertCount(2, $res); $this->assertTrue(in_array('bar', $res)); $this->assertTrue(in_array('bar2', $res)); } public function testCleanModeMatchingAnyTags(): void { $this->_instance->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('tag999')); $this->assertTrue(!!$this->_instance->load('bar')); $this->assertTrue(!!$this->_instance->load('bar2')); $this->assertTrue(!!$this->_instance->load('bar3')); } public function testCleanModeMatchingAnyTags2(): void { $this->_instance->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('tag1', 'tag999')); $this->assertTrue(!!$this->_instance->load('bar')); $this->assertFalse(!!$this->_instance->load('bar2')); $this->assertTrue(!!$this->_instance->load('bar3')); } public function testCleanModeMatchingAnyTags3(): void { $this->_instance->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('tag3', 'tag999')); $this->assertFalse(!!$this->_instance->load('bar')); $this->assertFalse(!!$this->_instance->load('bar2')); $this->assertFalse(!!$this->_instance->load('bar3')); } public function testCleanModeMatchingAnyTags4(): void { $this->_instance->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('tag1', 'tag4')); $this->assertFalse(!!$this->_instance->load('bar')); $this->assertFalse(!!$this->_instance->load('bar2')); $this->assertTrue(!!$this->_instance->load('bar3')); } public function testCleanModeMatchingAnyTags5(): void { $tags = array('tag1', 'tag4'); for ($i = 0; $i < self::LUA_MAX_C_STACK*5; $i++) { $this->_instance->save('foo', 'foo'.$i, $tags); } $this->assertGreaterThan(self::LUA_MAX_C_STACK, count($this->_instance->getIdsMatchingAnyTags($tags))); $this->_instance->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags); $this->assertCount(0, $this->_instance->getIdsMatchingAnyTags($tags)); } public function testCleanModeMatchingAnyTags6(): void { $tags = array(); for ($i = 0; $i < self::LUA_MAX_C_STACK*5; $i++) { $tags[] = 'baz'.$i; } $this->_instance->save('foo', 'foo', $tags); $_tags = array(end($tags)); $this->assertCount(1, $this->_instance->getIdsMatchingAnyTags($_tags)); $this->_instance->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $_tags); $this->assertCount(0, $this->_instance->getIdsMatchingAnyTags($_tags)); } public function testScriptsCaching(): void { $this->_instance->___scriptFlush(); $this->assertEquals([], $this->_instance->___checkScriptsExist()); $this->_instance->save('foo', 'bar', ['x','y']); $this->assertEquals(['save'], $this->_instance->___checkScriptsExist()); $this->_instance->___scriptFlush(); $this->_instance->clean(Zend_Cache::CLEANING_MODE_OLD); $this->assertEquals(['garbage'], $this->_instance->___checkScriptsExist()); $this->_instance->___scriptFlush(); $this->_instance->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, ['x']); $this->assertEquals(['clean'], $this->_instance->___checkScriptsExist()); } }