‪TYPO3CMS  9.5
RedisBackendTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Psr\Log\LoggerInterface;
21 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
22 
32 class ‪RedisBackendTest extends FunctionalTestCase
33 {
37  protected function ‪setUp()
38  {
39  if (!getenv('typo3TestingRedisHost')) {
40  $this->markTestSkipped('environment variable "typo3TestingRedisHost" must be set to run this test');
41  }
42  // Note we assume that if that typo3TestingRedisHost env is set, we can use that for testing,
43  // there is no test to see if the daemon is actually up and running. Tests will fail if env
44  // is set but daemon is down.
45 
46  parent::setUp();
47  }
48 
52  protected function ‪setUpSubject(array $backendOptions = []): ‪RedisBackend
53  {
54  // We know this env is set, otherwise setUp() would skip the tests
55  $backendOptions['hostname'] = getenv('typo3TestingRedisHost');
56  // If typo3TestingRedisPort env is set, use it, otherwise fall back to standard port
57  $env = getenv('typo3TestingRedisPort');
58  $backendOptions['port'] = is_string($env) ? (int)$env : 6379;
59 
60  $frontendProphecy = $this->prophesize(FrontendInterface::class);
61  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
62 
63  ‪$GLOBALS['TYPO3_CONF_VARS']['LOG'] = 'only needed for logger initialisation';
64  $subject = new ‪RedisBackend('Testing', $backendOptions);
65  $subject->setLogger($this->prophesize(LoggerInterface::class)->reveal());
66  $subject->setCache($frontendProphecy->reveal());
67  $subject->initializeObject();
68  $subject->flush();
69  return $subject;
70  }
71 
75  protected function ‪setUpRedis(): \Redis
76  {
77  // We know this env is set, otherwise setUp() would skip the tests
78  $redisHost = getenv('typo3TestingRedisHost');
79  // If typo3TestingRedisPort env is set, use it, otherwise fall back to standard port
80  $env = getenv('typo3TestingRedisPort');
81  $redisPort = is_string($env) ? (int)$env : 6379;
82 
83  $redis = new \Redis();
84  $redis->connect($redisHost, $redisPort);
85  return $redis;
86  }
87 
92  {
93  $this->expectException(\InvalidArgumentException::class);
94  $this->expectExceptionCode(1279763057);
95 
96  $this->‪setUpSubject(['database' => 'foo']);
97  }
98 
103  {
104  $this->expectException(\InvalidArgumentException::class);
105  $this->expectExceptionCode(1279763534);
106 
107  $this->‪setUpSubject(['database' => -1]);
108  }
109 
114  {
115  $this->expectException(\InvalidArgumentException::class);
116  $this->expectExceptionCode(1289679153);
117 
118  $this->‪setUpSubject(['compression' => 'foo']);
119  }
120 
125  {
126  $this->expectException(\InvalidArgumentException::class);
127  $this->expectExceptionCode(1289679154);
128 
129  $this->‪setUpSubject(['compressionLevel' => 'foo']);
130  }
131 
136  {
137  $this->expectException(\InvalidArgumentException::class);
138  $this->expectExceptionCode(1289679155);
139 
140  $this->‪setUpSubject(['compressionLevel' => 11]);
141  }
142 
147  {
148  $this->expectException(\InvalidArgumentException::class);
149  $this->expectExceptionCode(1487849315);
150 
151  $this->‪setUpSubject(['connectionTimeout' => 'foo']);
152  }
153 
158  {
159  $this->expectException(\InvalidArgumentException::class);
160  $this->expectExceptionCode(1487849326);
161 
162  $this->‪setUpSubject(['connectionTimeout' => -1]);
163  }
164 
169  {
170  $this->expectException(\InvalidArgumentException::class);
171  $this->expectExceptionCode(1377006651);
172 
173  $subject = $this->‪setUpSubject();
174  $subject->set([], 'data');
175  }
176 
181  {
182  $this->expectException(InvalidDataException::class);
183  $this->expectExceptionCode(1279469941);
184 
185  $subject = $this->‪setUpSubject();
186  $subject->set($this->getUniqueId('identifier'), []);
187  }
188 
193  {
194  $this->expectException(\InvalidArgumentException::class);
195  $this->expectExceptionCode(1279487573);
196 
197  $subject = $this->‪setUpSubject();
198  $subject->set($this->getUniqueId('identifier'), 'data', [], -42);
199  }
200 
205  {
206  $this->expectException(\InvalidArgumentException::class);
207  $this->expectExceptionCode(1279488008);
208 
209  $subject = $this->‪setUpSubject();
210  $subject->set($this->getUniqueId('identifier'), 'data', [], []);
211  }
212 
217  {
218  $redis = $this->‪setUpRedis();
219  $redis->select(1);
220  $subject = $this->‪setUpSubject(['database' => 1]);
221  $identifier = $this->getUniqueId('identifier');
222  $subject->set($identifier, 'data');
223  $result = $redis->exists('identData:' . $identifier);
224  if (is_int($result)) {
225  // Since 3.1.4 of phpredis/phpredis the return types has been changed
226  $result = (bool)$result;
227  }
228  $this->assertTrue($result);
229  }
230 
235  {
236  $subject = $this->‪setUpSubject();
237  $redis = $this->‪setUpRedis();
238  $identifier = $this->getUniqueId('identifier');
239  $subject->set($identifier, 'data');
240  $this->assertSame(\Redis::REDIS_STRING, $redis->type('identData:' . $identifier));
241  }
242 
247  {
248  $subject = $this->‪setUpSubject();
249  $redis = $this->‪setUpRedis();
250  $identifier = $this->getUniqueId('identifier');
251  $defaultLifetime = 42;
252  $subject->setDefaultLifetime($defaultLifetime);
253  $subject->set($identifier, 'data');
254  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
255  $this->assertSame($defaultLifetime, $lifetimeRegisteredInBackend);
256  }
257 
262  {
263  $subject = $this->‪setUpSubject();
264  $redis = $this->‪setUpRedis();
265  $identifier = $this->getUniqueId('identifier');
266  $lifetime = 43;
267  $subject->set($identifier, 'data', [], $lifetime);
268  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
269  $this->assertSame($lifetime, $lifetimeRegisteredInBackend);
270  }
271 
276  {
277  $subject = $this->‪setUpSubject();
278  $redis = $this->‪setUpRedis();
279  $identifier = $this->getUniqueId('identifier');
280  $subject->set($identifier, 'data', [], 0);
281  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
282  $this->assertSame(31536000, $lifetimeRegisteredInBackend);
283  }
284 
289  {
290  $subject = $this->‪setUpSubject();
291  $data = 'data 1';
292  $identifier = $this->getUniqueId('identifier');
293  $subject->set($identifier, $data);
294  $otherData = 'data 2';
295  $subject->set($identifier, $otherData);
296  $fetchedData = $subject->get($identifier);
297  $this->assertSame($otherData, $fetchedData);
298  }
299 
304  {
305  $subject = $this->‪setUpSubject();
306  $redis = $this->‪setUpRedis();
307  $data = 'data';
308  $identifier = $this->getUniqueId('identifier');
309  $subject->set($identifier, $data);
310  $lifetime = 42;
311  $subject->set($identifier, $data, [], $lifetime);
312  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
313  $this->assertSame($lifetime, $lifetimeRegisteredInBackend);
314  }
315 
320  {
321  $subject = $this->‪setUpSubject();
322  $redis = $this->‪setUpRedis();
323  $data = 'data';
324  $identifier = $this->getUniqueId('identifier');
325  $lifetime = 42;
326  $subject->set($identifier, $data, [], $lifetime);
327  $newDefaultLifetime = 43;
328  $subject->setDefaultLifetime($newDefaultLifetime);
329  $subject->set($identifier, $data, [], $newDefaultLifetime);
330  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
331  $this->assertSame($newDefaultLifetime, $lifetimeRegisteredInBackend);
332  }
333 
338  {
339  $subject = $this->‪setUpSubject();
340  $redis = $this->‪setUpRedis();
341  $data = 'data';
342  $identifier = $this->getUniqueId('identifier');
343  $lifetime = 42;
344  $subject->set($identifier, $data, [], $lifetime);
345  $subject->set($identifier, $data, [], 0);
346  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
347  $this->assertSame(31536000, $lifetimeRegisteredInBackend);
348  }
349 
354  {
355  $subject = $this->‪setUpSubject();
356  $redis = $this->‪setUpRedis();
357  $identifier = $this->getUniqueId('identifier');
358  $subject->set($identifier, 'data', ['tag']);
359  $this->assertSame(\Redis::REDIS_SET, $redis->type('identTags:' . $identifier));
360  }
361 
366  {
367  $subject = $this->‪setUpSubject();
368  $redis = $this->‪setUpRedis();
369  $identifier = $this->getUniqueId('identifier');
370  $tags = ['thatTag', 'thisTag'];
371  $subject->set($identifier, 'data', $tags);
372  $savedTags = $redis->sMembers('identTags:' . $identifier);
373  sort($savedTags);
374  $this->assertSame($tags, $savedTags);
375  }
376 
381  {
382  $subject = $this->‪setUpSubject();
383  $redis = $this->‪setUpRedis();
384  $identifier = $this->getUniqueId('identifier');
385  $tags = ['fooTag', 'barTag'];
386  $subject->set($identifier, 'data', $tags);
387  $subject->set($identifier, 'data', []);
388  $this->assertSame([], $redis->sMembers('identTags:' . $identifier));
389  }
390 
395  {
396  $subject = $this->‪setUpSubject();
397  $redis = $this->‪setUpRedis();
398  $identifier = $this->getUniqueId('identifier');
399  $firstTagSet = ['tag1', 'tag2', 'tag3', 'tag4'];
400  $subject->set($identifier, 'data', $firstTagSet);
401  $secondTagSet = ['tag1', 'tag3'];
402  $subject->set($identifier, 'data', $secondTagSet);
403  $actualTagSet = $redis->sMembers('identTags:' . $identifier);
404  sort($actualTagSet);
405  $this->assertSame($secondTagSet, $actualTagSet);
406  }
407 
412  {
413  $subject = $this->‪setUpSubject();
414  $redis = $this->‪setUpRedis();
415  $identifier = $this->getUniqueId('identifier');
416  $tag = 'tag';
417  $subject->set($identifier, 'data', [$tag]);
418  $this->assertSame(\Redis::REDIS_SET, $redis->type('tagIdents:' . $tag));
419  }
420 
425  {
426  $subject = $this->‪setUpSubject();
427  $redis = $this->‪setUpRedis();
428  $identifier = $this->getUniqueId('identifier');
429  $tag = 'thisTag';
430  $subject->set($identifier, 'data', [$tag]);
431  $savedTagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
432  $this->assertSame([$identifier], $savedTagToIdentifiersMemberArray);
433  }
434 
439  {
440  $subject = $this->‪setUpSubject();
441  $redis = $this->‪setUpRedis();
442  $firstIdentifier = $this->getUniqueId('identifier1-');
443  $tag = 'thisTag';
444  $subject->set($firstIdentifier, 'data', [$tag]);
445  $secondIdentifier = $this->getUniqueId('identifier2-');
446  $subject->set($secondIdentifier, 'data', [$tag]);
447  $savedTagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
448  sort($savedTagToIdentifiersMemberArray);
449  $identifierArray = [$firstIdentifier, $secondIdentifier];
450  sort($identifierArray);
451  $this->assertSame([$firstIdentifier, $secondIdentifier], $savedTagToIdentifiersMemberArray);
452  }
453 
458  {
459  $subject = $this->‪setUpSubject();
460  $redis = $this->‪setUpRedis();
461  $identifier = $this->getUniqueId('identifier');
462  $tag = 'thisTag';
463  $subject->set($identifier, 'data', [$tag]);
464  $subject->set($identifier, 'data', []);
465  $savedTagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
466  $this->assertSame([], $savedTagToIdentifiersMemberArray);
467  }
468 
473  {
474  $subject = $this->‪setUpSubject();
475  $redis = $this->‪setUpRedis();
476  $identifier = $this->getUniqueId('identifier');
477  $subject->set($identifier, 'data');
478  $tag = 'thisTag';
479  $subject->set($identifier, 'data', [$tag]);
480  $savedTagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
481  $this->assertSame([$identifier], $savedTagToIdentifiersMemberArray);
482  }
483 
488  {
489  $subject = $this->‪setUpSubject([
490  'compression' => true
491  ]);
492  $redis = $this->‪setUpRedis();
493  $identifier = $this->getUniqueId('identifier');
494  $data = 'some data ' . microtime();
495  $subject->set($identifier, $data);
496  $uncompresedStoredData = '';
497  try {
498  $uncompresedStoredData = @gzuncompress($redis->get('identData:' . $identifier));
499  } catch (\‪Exception $e) {
500  }
501  $this->assertEquals($data, $uncompresedStoredData, 'Original and compressed data don\'t match');
502  }
503 
508  {
509  $subject = $this->‪setUpSubject([
510  'compression' => true,
511  'compressionLevel' => 0
512  ]);
513  $redis = $this->‪setUpRedis();
514  $identifier = $this->getUniqueId('identifier');
515  $data = 'some data ' . microtime();
516  $subject->set($identifier, $data);
517  $this->assertGreaterThan(0, substr_count($redis->get('identData:' . $identifier), $data), 'Plaintext data not found');
518  }
519 
524  {
525  $this->expectException(\InvalidArgumentException::class);
526  $this->expectExceptionCode(1377006653);
527 
528  $subject = $this->‪setUpSubject();
529  $subject->has([]);
530  }
531 
536  {
537  $subject = $this->‪setUpSubject();
538  $identifier = $this->getUniqueId('identifier');
539  $this->assertFalse($subject->has($identifier));
540  }
541 
546  {
547  $subject = $this->‪setUpSubject();
548  $identifier = $this->getUniqueId('identifier');
549  $subject->set($identifier, 'data');
550  $this->assertTrue($subject->has($identifier));
551  }
552 
557  {
558  $this->expectException(\InvalidArgumentException::class);
559  //@todo Add exception code with redis extension
560 
561  $subject = $this->‪setUpSubject();
562  $subject->get([]);
563  }
564 
569  {
570  $subject = $this->‪setUpSubject([
571  'compression' => true
572  ]);
573  $data = 'data';
574  $identifier = $this->getUniqueId('identifier');
575  $subject->set($identifier, $data);
576  $fetchedData = $subject->get($identifier);
577  $this->assertSame($data, $fetchedData);
578  }
579 
584  {
585  $subject = $this->‪setUpSubject();
586  $data = 'data';
587  $identifier = $this->getUniqueId('identifier');
588  $subject->set($identifier, $data);
589  $fetchedData = $subject->get($identifier);
590  $this->assertSame($data, $fetchedData);
591  }
592 
597  {
598  $this->expectException(\InvalidArgumentException::class);
599  $this->expectExceptionCode(1377006654);
600 
601  $subject = $this->‪setUpSubject();
602  $subject->remove([]);
603  }
604 
609  {
610  $subject = $this->‪setUpSubject();
611  $this->assertFalse($subject->remove($this->getUniqueId('identifier')));
612  }
613 
618  {
619  $subject = $this->‪setUpSubject();
620  $identifier = $this->getUniqueId('identifier');
621  $subject->set($identifier, 'data');
622  $this->assertTrue($subject->remove($identifier));
623  }
624 
629  {
630  $subject = $this->‪setUpSubject();
631  $identifier = $this->getUniqueId('identifier');
632  $subject->set($identifier, 'data');
633  $subject->remove($identifier);
634  $this->assertFalse($subject->has($identifier));
635  }
636 
641  {
642  $subject = $this->‪setUpSubject();
643  $redis = $this->‪setUpRedis();
644  $identifier = $this->getUniqueId('identifier');
645  $tag = 'thisTag';
646  $subject->set($identifier, 'data', [$tag]);
647  $subject->remove($identifier);
648  $result = $redis->exists('identTags:' . $identifier);
649  if (is_int($result)) {
650  // Since 3.1.4 of phpredis/phpredis the return types has been changed
651  $result = (bool)$result;
652  }
653  $this->assertFalse($result);
654  }
655 
660  {
661  $subject = $this->‪setUpSubject();
662  $redis = $this->‪setUpRedis();
663  $identifier = $this->getUniqueId('identifier');
664  $tag = 'thisTag';
665  $subject->set($identifier, 'data', [$tag]);
666  $subject->remove($identifier);
667  $tagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
668  $this->assertSame([], $tagToIdentifiersMemberArray);
669  }
670 
675  {
676  $subject = $this->‪setUpSubject();
677  $redis = $this->‪setUpRedis();
678  $firstIdentifier = $this->getUniqueId('identifier');
679  $secondIdentifier = $this->getUniqueId('identifier');
680  $tag = 'thisTag';
681  $subject->set($firstIdentifier, 'data', [$tag]);
682  $subject->set($secondIdentifier, 'data', [$tag]);
683  $subject->remove($firstIdentifier);
684  $tagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
685  $this->assertSame([$secondIdentifier], $tagToIdentifiersMemberArray);
686  }
687 
692  {
693  $this->expectException(\InvalidArgumentException::class);
694  $this->expectExceptionCode(1377006655);
695 
696  $subject = $this->‪setUpSubject();
697  $subject->findIdentifiersByTag([]);
698  }
699 
704  {
705  $subject = $this->‪setUpSubject();
706  $this->assertSame([], $subject->findIdentifiersByTag('thisTag'));
707  }
708 
713  {
714  $subject = $this->‪setUpSubject();
715  $firstIdentifier = $this->getUniqueId('identifier1-');
716  $secondIdentifier = $this->getUniqueId('identifier2-');
717  $thirdIdentifier = $this->getUniqueId('identifier3-');
718  $tagsForFirstIdentifier = ['thisTag'];
719  $tagsForSecondIdentifier = ['thatTag'];
720  $tagsForThirdIdentifier = ['thisTag', 'thatTag'];
721  $subject->set($firstIdentifier, 'data', $tagsForFirstIdentifier);
722  $subject->set($secondIdentifier, 'data', $tagsForSecondIdentifier);
723  $subject->set($thirdIdentifier, 'data', $tagsForThirdIdentifier);
724  $expectedResult = [$firstIdentifier, $thirdIdentifier];
725  $actualResult = $subject->findIdentifiersByTag('thisTag');
726  sort($actualResult);
727  $this->assertSame($expectedResult, $actualResult);
728  }
729 
734  {
735  $subject = $this->‪setUpSubject();
736  $redis = $this->‪setUpRedis();
737  $identifier = $this->getUniqueId('identifier');
738  $subject->set($identifier, 'data');
739  $subject->flush();
740  $this->assertSame([], $redis->getKeys('*'));
741  }
742 
747  {
748  $this->expectException(\InvalidArgumentException::class);
749  $this->expectExceptionCode(1377006656);
750 
751  $subject = $this->‪setUpSubject();
752  $subject->flushByTag([]);
753  }
754 
759  {
760  $subject = $this->‪setUpSubject();
761  $identifier = $this->getUniqueId('identifier');
762  $subject->set($identifier . 'A', 'data', ['tag1']);
763  $subject->set($identifier . 'B', 'data', ['tag2']);
764  $subject->set($identifier . 'C', 'data', ['tag1', 'tag2']);
765  $subject->flushByTag('tag1');
766  $expectedResult = [false, true, false];
767  $actualResult = [
768  $subject->has($identifier . 'A'),
769  $subject->has($identifier . 'B'),
770  $subject->has($identifier . 'C')
771  ];
772  $this->assertSame($expectedResult, $actualResult);
773  }
774 
779  {
780  $subject = $this->‪setUpSubject();
781  $identifier = $this->getUniqueId('identifier');
782  $subject->set($identifier . 'A', 'data', ['tag1']);
783  $subject->set($identifier . 'B', 'data', ['tag2']);
784  $subject->set($identifier . 'C', 'data', ['tag1', 'tag2']);
785  $subject->set($identifier . 'D', 'data', ['tag3']);
786  $subject->flushByTags(['tag1', 'tag2']);
787  $expectedResult = [false, false, false, true];
788  $actualResult = [
789  $subject->has($identifier . 'A'),
790  $subject->has($identifier . 'B'),
791  $subject->has($identifier . 'C'),
792  $subject->has($identifier . 'D')
793  ];
794  $this->assertSame($expectedResult, $actualResult);
795  }
796 
801  {
802  $subject = $this->‪setUpSubject();
803  $redis = $this->‪setUpRedis();
804  $identifier = $this->getUniqueId('identifier');
805  $subject->set($identifier . 'A', 'data', ['tag1']);
806  $subject->set($identifier . 'C', 'data', ['tag1', 'tag2']);
807  $subject->flushByTag('tag1');
808  $this->assertSame([], $redis->getKeys('temp*'));
809  }
810 
815  {
816  $subject = $this->‪setUpSubject();
817  $redis = $this->‪setUpRedis();
818  $identifier = $this->getUniqueId('identifier');
819  $tag = 'tag1';
820  $subject->set($identifier, 'data', [$tag]);
821  $subject->flushByTag($tag);
822  $result = $redis->exists('identTags:' . $identifier);
823  if (is_int($result)) {
824  // Since 3.1.4 of phpredis/phpredis the return types has been changed
825  $result = (bool)$result;
826  }
827  $this->assertFalse($result);
828  }
829 
834  {
835  $subject = $this->‪setUpSubject();
836  $redis = $this->‪setUpRedis();
837  $identifierToBeRemoved = $this->getUniqueId('identifier');
838  $tagToRemove = 'tag1';
839  $subject->set($identifierToBeRemoved, 'data', [$tagToRemove]);
840  $identifierNotToBeRemoved = $this->getUniqueId('identifier');
841  $tagNotToRemove = 'tag2';
842  $subject->set($identifierNotToBeRemoved, 'data', [$tagNotToRemove]);
843  $subject->flushByTag($tagToRemove);
844  $this->assertSame([$tagNotToRemove], $redis->sMembers('identTags:' . $identifierNotToBeRemoved));
845  }
846 
851  {
852  $subject = $this->‪setUpSubject();
853  $redis = $this->‪setUpRedis();
854  $identifier = $this->getUniqueId('identifier');
855  $tag = 'tag1';
856  $subject->set($identifier, 'data', [$tag]);
857  $subject->flushByTag($tag);
858  $result = $redis->exists('tagIdents:' . $tag);
859  if (is_int($result)) {
860  // Since 3.1.4 of phpredis/phpredis the return types has been changed
861  $result = (bool)$result;
862  }
863  $this->assertFalse($result);
864  }
865 
870  {
871  $subject = $this->‪setUpSubject();
872  $redis = $this->‪setUpRedis();
873  $identifier = $this->getUniqueId('identifier');
874  $subject->set($identifier . 'A', 'data', ['tag1', 'tag2']);
875  $subject->set($identifier . 'B', 'data', ['tag1', 'tag2']);
876  $subject->set($identifier . 'C', 'data', ['tag2']);
877  $subject->flushByTag('tag1');
878  $this->assertSame([$identifier . 'C'], $redis->sMembers('tagIdents:tag2'));
879  }
880 
885  {
886  $subject = $this->‪setUpSubject();
887  $redis = $this->‪setUpRedis();
888  $identifier = $this->getUniqueId('identifier');
889  $subject->set($identifier . 'A', 'data', ['tag']);
890  $subject->set($identifier . 'B', 'data', ['tag']);
891  $redis->del('identData:' . $identifier . 'A');
892  $subject->collectGarbage();
893  $result = $redis->exists('identData:' . $identifier . 'B');
894  if (is_int($result)) {
895  // Since 3.1.4 of phpredis/phpredis the return types has been changed
896  $result = (bool)$result;
897  }
898  $this->assertTrue($result);
899  }
900 
905  {
906  $subject = $this->‪setUpSubject();
907  $redis = $this->‪setUpRedis();
908  $identifier = $this->getUniqueId('identifier');
909  $subject->set($identifier . 'A', 'data', ['tag']);
910  $subject->set($identifier . 'B', 'data', ['tag']);
911  $redis->del('identData:' . $identifier . 'A');
912  $subject->collectGarbage();
913  $expectedResult = [false, true];
914  $resultA = $redis->exists('identTags:' . $identifier . 'A');
915  $resultB = $redis->exists('identTags:' . $identifier . 'B');
916  if (is_int($resultA)) {
917  // Since 3.1.4 of phpredis/phpredis the return types has been changed
918  $resultA = (bool)$resultA;
919  }
920  if (is_int($resultB)) {
921  // Since 3.1.4 of phpredis/phpredis the return types has been changed
922  $resultB = (bool)$resultB;
923  }
924  $actualResult = [
925  $resultA,
926  $resultB
927  ];
928  $this->assertSame($expectedResult, $actualResult);
929  }
930 
935  {
936  $subject = $this->‪setUpSubject();
937  $redis = $this->‪setUpRedis();
938  $identifier = $this->getUniqueId('identifier');
939  $subject->set($identifier . 'A', 'data', ['tag1', 'tag2']);
940  $subject->set($identifier . 'B', 'data', ['tag2']);
941  $redis->del('identData:' . $identifier . 'A');
942  $subject->collectGarbage();
943  $expectedResult = [
944  [],
945  [$identifier . 'B']
946  ];
947  $actualResult = [
948  $redis->sMembers('tagIdents:tag1'),
949  $redis->sMembers('tagIdents:tag2')
950  ];
951  $this->assertSame($expectedResult, $actualResult);
952  }
953 }
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setUpRedis
‪setUpRedis()
Definition: RedisBackendTest.php:75
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setOverwritesExistingEntryWithNewDefaultLifetime
‪setOverwritesExistingEntryWithNewDefaultLifetime()
Definition: RedisBackendTest.php:319
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\findIdentifiersByTagReturnsAllIdentifiersTagedWithSpecifiedTag
‪findIdentifiersByTagReturnsAllIdentifiersTagedWithSpecifiedTag()
Definition: RedisBackendTest.php:712
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\getReturnsPreviouslySetEntry
‪getReturnsPreviouslySetEntry()
Definition: RedisBackendTest.php:583
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeReturnsTrueIfAnEntryWasDeleted
‪removeReturnsTrueIfAnEntryWasDeleted()
Definition: RedisBackendTest.php:617
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesEntryWithUnlimitedLifeTime
‪setSavesEntryWithUnlimitedLifeTime()
Definition: RedisBackendTest.php:275
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setDatabaseThrowsExceptionIfGivenDatabaseNumberIsNotAnInteger
‪setDatabaseThrowsExceptionIfGivenDatabaseNumberIsNotAnInteger()
Definition: RedisBackendTest.php:91
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend
Definition: MemcachedBackendTest.php:2
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\collectGarbageRemovesExpiredIdentifierFromTagsToIdentifierSet
‪collectGarbageRemovesExpiredIdentifierFromTagsToIdentifierSet()
Definition: RedisBackendTest.php:934
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesEntryWithSpecifiedLifeTime
‪setSavesEntryWithSpecifiedLifeTime()
Definition: RedisBackendTest.php:261
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setCompressionLevelThrowsExceptionIfCompressionLevelIsNotBetweenMinusOneAndNine
‪setCompressionLevelThrowsExceptionIfCompressionLevelIsNotBetweenMinusOneAndNine()
Definition: RedisBackendTest.php:135
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeReturnsFalseIfNoEntryWasDeleted
‪removeReturnsFalseIfNoEntryWasDeleted()
Definition: RedisBackendTest.php:608
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setStoresEntriesInSelectedDatabase
‪setStoresEntriesInSelectedDatabase()
Definition: RedisBackendTest.php:216
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\collectGarbageRemovesLeftOverIdentifierToTagsSet
‪collectGarbageRemovesLeftOverIdentifierToTagsSet()
Definition: RedisBackendTest.php:904
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\getReturnsPreviouslyCompressedSetEntry
‪getReturnsPreviouslyCompressedSetEntry()
Definition: RedisBackendTest.php:568
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setDatabaseThrowsExceptionIfGivenDatabaseNumberIsNegative
‪setDatabaseThrowsExceptionIfGivenDatabaseNumberIsNegative()
Definition: RedisBackendTest.php:102
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setOverwritesExistingEntryWithSpecifiedLifetime
‪setOverwritesExistingEntryWithSpecifiedLifetime()
Definition: RedisBackendTest.php:303
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setOverwritesExistingEntryWithNewData
‪setOverwritesExistingEntryWithNewData()
Definition: RedisBackendTest.php:288
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagRemovesTemporarySet
‪flushByTagRemovesTemporarySet()
Definition: RedisBackendTest.php:800
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeDeletesIdentifierFromTagToIdentifiersSetWithMultipleEntries
‪removeDeletesIdentifierFromTagToIdentifiersSetWithMultipleEntries()
Definition: RedisBackendTest.php:674
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagRemovesTagToIdentifiersSetOfGivenTag
‪flushByTagRemovesTagToIdentifiersSetOfGivenTag()
Definition: RedisBackendTest.php:850
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setThrowsExceptionIfIdentifierIsNotAString
‪setThrowsExceptionIfIdentifierIsNotAString()
Definition: RedisBackendTest.php:168
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\hasThrowsExceptionIfIdentifierIsNotAString
‪hasThrowsExceptionIfIdentifierIsNotAString()
Definition: RedisBackendTest.php:523
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesIdentifierInTagToIdentifiersSetOfSpecifiedTag
‪setSavesIdentifierInTagToIdentifiersSetOfSpecifiedTag()
Definition: RedisBackendTest.php:424
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagDoesNotRemoveIdentifierToTagsSetOfUnrelatedEntry
‪flushByTagDoesNotRemoveIdentifierToTagsSetOfUnrelatedEntry()
Definition: RedisBackendTest.php:833
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setUpSubject
‪setUpSubject(array $backendOptions=[])
Definition: RedisBackendTest.php:52
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\collectGarbageDoesNotRemoveNotExpiredIdentifierToDataEntry
‪collectGarbageDoesNotRemoveNotExpiredIdentifierToDataEntry()
Definition: RedisBackendTest.php:884
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setCompressionThrowsExceptionIfCompressionParameterIsNotOfTypeBoolean
‪setCompressionThrowsExceptionIfCompressionParameterIsNotOfTypeBoolean()
Definition: RedisBackendTest.php:113
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setAppendsSecondIdentifierInTagToIdentifiersEntry
‪setAppendsSecondIdentifierInTagToIdentifiersEntry()
Definition: RedisBackendTest.php:438
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeDeletesEntryFromCache
‪removeDeletesEntryFromCache()
Definition: RedisBackendTest.php:628
‪TYPO3\CMS\Core\Cache\Backend\RedisBackend
Definition: RedisBackend.php:30
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesSetDataTypeForIdentifierToTagsSet
‪setSavesSetDataTypeForIdentifierToTagsSet()
Definition: RedisBackendTest.php:353
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\hasReturnsFalseForNotExistingEntry
‪hasReturnsFalseForNotExistingEntry()
Definition: RedisBackendTest.php:535
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\hasReturnsTrueForPreviouslySetEntry
‪hasReturnsTrueForPreviouslySetEntry()
Definition: RedisBackendTest.php:545
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagsRemovesEntriesTaggedWithSpecifiedTags
‪flushByTagsRemovesEntriesTaggedWithSpecifiedTags()
Definition: RedisBackendTest.php:778
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeDeletesIdentifierFromTagToIdentifiersSet
‪removeDeletesIdentifierFromTagToIdentifiersSet()
Definition: RedisBackendTest.php:659
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setOverwritesExistingEntryWithNewUnlimitedLifetime
‪setOverwritesExistingEntryWithNewUnlimitedLifetime()
Definition: RedisBackendTest.php:337
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setRemovesIdentifierFromTagToIdentifiersEntryIfTagIsOmittedOnConsecutiveSet
‪setRemovesIdentifierFromTagToIdentifiersEntryIfTagIsOmittedOnConsecutiveSet()
Definition: RedisBackendTest.php:457
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagThrowsExceptionIfTagIsNotAString
‪flushByTagThrowsExceptionIfTagIsNotAString()
Definition: RedisBackendTest.php:746
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesStringDataTypeForIdentifierToDataEntry
‪setSavesStringDataTypeForIdentifierToDataEntry()
Definition: RedisBackendTest.php:234
‪TYPO3\CMS\Core\Cache\Exception\InvalidDataException
Definition: InvalidDataException.php:21
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesPlaintextDataWithEnabledCompressionAndCompressionLevel0
‪setSavesPlaintextDataWithEnabledCompressionAndCompressionLevel0()
Definition: RedisBackendTest.php:507
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setRemovesAllPreviouslySetTagsFromIdentifierToTagsSet
‪setRemovesAllPreviouslySetTagsFromIdentifierToTagsSet()
Definition: RedisBackendTest.php:380
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesSetDataTypeForTagToIdentifiersSet
‪setSavesSetDataTypeForTagToIdentifiersSet()
Definition: RedisBackendTest.php:411
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setThrowsExceptionIfLifetimeIsNegative
‪setThrowsExceptionIfLifetimeIsNegative()
Definition: RedisBackendTest.php:192
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagRemovesIdentifierToTagsSetOfEntryTaggedWithGivenTag
‪flushByTagRemovesIdentifierToTagsSetOfEntryTaggedWithGivenTag()
Definition: RedisBackendTest.php:814
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagRemovesEntriesTaggedWithSpecifiedTag
‪flushByTagRemovesEntriesTaggedWithSpecifiedTag()
Definition: RedisBackendTest.php:758
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeDeletesIdentifierToTagEntry
‪removeDeletesIdentifierToTagEntry()
Definition: RedisBackendTest.php:640
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesEntryWithDefaultLifeTime
‪setSavesEntryWithDefaultLifeTime()
Definition: RedisBackendTest.php:246
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setUp
‪setUp()
Definition: RedisBackendTest.php:37
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setThrowsExceptionIfDataIsNotAString
‪setThrowsExceptionIfDataIsNotAString()
Definition: RedisBackendTest.php:180
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushRemovesAllEntriesFromCache
‪flushRemovesAllEntriesFromCache()
Definition: RedisBackendTest.php:733
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\findIdentifiersByTagReturnsEmptyArrayForNotExistingTag
‪findIdentifiersByTagReturnsEmptyArrayForNotExistingTag()
Definition: RedisBackendTest.php:703
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeThrowsExceptionIfIdentifierIsNotAString
‪removeThrowsExceptionIfIdentifierIsNotAString()
Definition: RedisBackendTest.php:596
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\getThrowsExceptionIfIdentifierIsNotAString
‪getThrowsExceptionIfIdentifierIsNotAString()
Definition: RedisBackendTest.php:556
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setRemovesMultiplePreviouslySetTagsFromIdentifierToTagsSet
‪setRemovesMultiplePreviouslySetTagsFromIdentifierToTagsSet()
Definition: RedisBackendTest.php:394
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesSpecifiedTagsInIdentifierToTagsSet
‪setSavesSpecifiedTagsInIdentifierToTagsSet()
Definition: RedisBackendTest.php:365
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setCompressionLevelThrowsExceptionIfCompressionLevelIsNotInteger
‪setCompressionLevelThrowsExceptionIfCompressionLevelIsNotInteger()
Definition: RedisBackendTest.php:124
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setAddsIdentifierInTagToIdentifiersEntryIfTagIsAddedOnConsecutiveSet
‪setAddsIdentifierInTagToIdentifiersEntryIfTagIsAddedOnConsecutiveSet()
Definition: RedisBackendTest.php:472
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest
Definition: RedisBackendTest.php:33
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setConnectionTimeoutThrowsExceptionIfConnectionTimeoutIsNotInteger
‪setConnectionTimeoutThrowsExceptionIfConnectionTimeoutIsNotInteger()
Definition: RedisBackendTest.php:146
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagRemovesIdentifiersTaggedWithGivenTagFromTagToIdentifiersSets
‪flushByTagRemovesIdentifiersTaggedWithGivenTagFromTagToIdentifiersSets()
Definition: RedisBackendTest.php:869
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesCompressedDataWithEnabledCompression
‪setSavesCompressedDataWithEnabledCompression()
Definition: RedisBackendTest.php:487
‪TYPO3\CMS\Core\Cache\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setConnectionTimeoutThrowsExceptionIfConnectionTimeoutIsNegative
‪setConnectionTimeoutThrowsExceptionIfConnectionTimeoutIsNegative()
Definition: RedisBackendTest.php:157
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setThrowsExceptionIfLifetimeIsNotNullOrAnInteger
‪setThrowsExceptionIfLifetimeIsNotNullOrAnInteger()
Definition: RedisBackendTest.php:204
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\findIdentifiersByTagThrowsExceptionIfTagIsNotAString
‪findIdentifiersByTagThrowsExceptionIfTagIsNotAString()
Definition: RedisBackendTest.php:691