‪TYPO3CMS  10.4
RedisBackendTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Log\LoggerInterface;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
34 class ‪RedisBackendTest extends FunctionalTestCase
35 {
39  protected function ‪setUp(): void
40  {
41  if (!getenv('typo3TestingRedisHost')) {
42  self::markTestSkipped('environment variable "typo3TestingRedisHost" must be set to run this test');
43  }
44  // Note we assume that if that typo3TestingRedisHost env is set, we can use that for testing,
45  // there is no test to see if the daemon is actually up and running. Tests will fail if env
46  // is set but daemon is down.
47 
48  parent::setUp();
49  }
50 
54  protected function ‪setUpSubject(array $backendOptions = []): ‪RedisBackend
55  {
56  // We know this env is set, otherwise setUp() would skip the tests
57  $backendOptions['hostname'] = getenv('typo3TestingRedisHost');
58  // If typo3TestingRedisPort env is set, use it, otherwise fall back to standard port
59  $env = getenv('typo3TestingRedisPort');
60  $backendOptions['port'] = is_string($env) ? (int)$env : 6379;
61 
62  $frontendProphecy = $this->prophesize(FrontendInterface::class);
63  $frontendProphecy->getIdentifier()->willReturn('pages');
64 
65  ‪$GLOBALS['TYPO3_CONF_VARS']['LOG'] = 'only needed for logger initialisation';
66  $subject = new ‪RedisBackend('Testing', $backendOptions);
67  $subject->setLogger($this->prophesize(LoggerInterface::class)->reveal());
68  $subject->setCache($frontendProphecy->reveal());
69  $subject->initializeObject();
70  $subject->flush();
71  return $subject;
72  }
73 
77  protected function ‪setUpRedis(): \Redis
78  {
79  // We know this env is set, otherwise setUp() would skip the tests
80  $redisHost = getenv('typo3TestingRedisHost');
81  // If typo3TestingRedisPort env is set, use it, otherwise fall back to standard port
82  $env = getenv('typo3TestingRedisPort');
83  $redisPort = is_string($env) ? (int)$env : 6379;
84 
85  $redis = new \Redis();
86  $redis->connect($redisHost, $redisPort);
87  return $redis;
88  }
89 
94  {
95  $this->expectException(\InvalidArgumentException::class);
96  $this->expectExceptionCode(1279763057);
97 
98  $this->‪setUpSubject(['database' => 'foo']);
99  }
100 
105  {
106  $this->expectException(\InvalidArgumentException::class);
107  $this->expectExceptionCode(1279763534);
108 
109  $this->‪setUpSubject(['database' => -1]);
110  }
111 
116  {
117  $this->expectException(\InvalidArgumentException::class);
118  $this->expectExceptionCode(1289679153);
119 
120  $this->‪setUpSubject(['compression' => 'foo']);
121  }
122 
127  {
128  $this->expectException(\InvalidArgumentException::class);
129  $this->expectExceptionCode(1289679154);
130 
131  $this->‪setUpSubject(['compressionLevel' => 'foo']);
132  }
133 
138  {
139  $this->expectException(\InvalidArgumentException::class);
140  $this->expectExceptionCode(1289679155);
141 
142  $this->‪setUpSubject(['compressionLevel' => 11]);
143  }
144 
149  {
150  $this->expectException(\InvalidArgumentException::class);
151  $this->expectExceptionCode(1487849315);
152 
153  $this->‪setUpSubject(['connectionTimeout' => 'foo']);
154  }
155 
160  {
161  $this->expectException(\InvalidArgumentException::class);
162  $this->expectExceptionCode(1487849326);
163 
164  $this->‪setUpSubject(['connectionTimeout' => -1]);
165  }
166 
171  {
172  $this->expectException(\InvalidArgumentException::class);
173  $this->expectExceptionCode(1377006651);
174 
175  $subject = $this->‪setUpSubject();
176  $subject->set([], 'data');
177  }
178 
183  {
184  $this->expectException(InvalidDataException::class);
185  $this->expectExceptionCode(1279469941);
186 
187  $subject = $this->‪setUpSubject();
188  $subject->set(‪StringUtility::getUniqueId('identifier'), []);
189  }
190 
195  {
196  $this->expectException(\InvalidArgumentException::class);
197  $this->expectExceptionCode(1279487573);
198 
199  $subject = $this->‪setUpSubject();
200  $subject->set(‪StringUtility::getUniqueId('identifier'), 'data', [], -42);
201  }
202 
207  {
208  $this->expectException(\InvalidArgumentException::class);
209  $this->expectExceptionCode(1279488008);
210 
211  $subject = $this->‪setUpSubject();
212  $subject->set(‪StringUtility::getUniqueId('identifier'), 'data', [], []);
213  }
214 
219  {
220  $redis = $this->‪setUpRedis();
221  $redis->select(1);
222  $subject = $this->‪setUpSubject(['database' => 1]);
223  $identifier = ‪StringUtility::getUniqueId('identifier');
224  $subject->set($identifier, 'data');
225  $result = $redis->exists('identData:' . $identifier);
226  if (is_int($result)) {
227  // Since 3.1.4 of phpredis/phpredis the return types has been changed
228  $result = (bool)$result;
229  }
230  self::assertTrue($result);
231  }
232 
237  {
238  $subject = $this->‪setUpSubject();
239  $redis = $this->‪setUpRedis();
240  $identifier = ‪StringUtility::getUniqueId('identifier');
241  $subject->set($identifier, 'data');
242  self::assertSame(\Redis::REDIS_STRING, $redis->type('identData:' . $identifier));
243  }
244 
249  {
250  $subject = $this->‪setUpSubject();
251  $redis = $this->‪setUpRedis();
252  $identifier = ‪StringUtility::getUniqueId('identifier');
253  $defaultLifetime = 42;
254  $subject->setDefaultLifetime($defaultLifetime);
255  $subject->set($identifier, 'data');
256  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
257  self::assertSame($defaultLifetime, $lifetimeRegisteredInBackend);
258  }
259 
264  {
265  $subject = $this->‪setUpSubject();
266  $redis = $this->‪setUpRedis();
267  $identifier = ‪StringUtility::getUniqueId('identifier');
268  $lifetime = 43;
269  $subject->set($identifier, 'data', [], $lifetime);
270  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
271  self::assertSame($lifetime, $lifetimeRegisteredInBackend);
272  }
273 
278  {
279  $subject = $this->‪setUpSubject();
280  $redis = $this->‪setUpRedis();
281  $identifier = ‪StringUtility::getUniqueId('identifier');
282  $subject->set($identifier, 'data', [], 0);
283  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
284  self::assertSame(31536000, $lifetimeRegisteredInBackend);
285  }
286 
291  {
292  $subject = $this->‪setUpSubject();
293  $data = 'data 1';
294  $identifier = ‪StringUtility::getUniqueId('identifier');
295  $subject->set($identifier, $data);
296  $otherData = 'data 2';
297  $subject->set($identifier, $otherData);
298  $fetchedData = $subject->get($identifier);
299  self::assertSame($otherData, $fetchedData);
300  }
301 
306  {
307  $subject = $this->‪setUpSubject();
308  $redis = $this->‪setUpRedis();
309  $data = 'data';
310  $identifier = ‪StringUtility::getUniqueId('identifier');
311  $subject->set($identifier, $data);
312  $lifetime = 42;
313  $subject->set($identifier, $data, [], $lifetime);
314  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
315  self::assertSame($lifetime, $lifetimeRegisteredInBackend);
316  }
317 
322  {
323  $subject = $this->‪setUpSubject();
324  $redis = $this->‪setUpRedis();
325  $data = 'data';
326  $identifier = ‪StringUtility::getUniqueId('identifier');
327  $lifetime = 42;
328  $subject->set($identifier, $data, [], $lifetime);
329  $newDefaultLifetime = 43;
330  $subject->setDefaultLifetime($newDefaultLifetime);
331  $subject->set($identifier, $data, [], $newDefaultLifetime);
332  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
333  self::assertSame($newDefaultLifetime, $lifetimeRegisteredInBackend);
334  }
335 
340  {
341  $subject = $this->‪setUpSubject();
342  $redis = $this->‪setUpRedis();
343  $data = 'data';
344  $identifier = ‪StringUtility::getUniqueId('identifier');
345  $lifetime = 42;
346  $subject->set($identifier, $data, [], $lifetime);
347  $subject->set($identifier, $data, [], 0);
348  $lifetimeRegisteredInBackend = $redis->ttl('identData:' . $identifier);
349  self::assertSame(31536000, $lifetimeRegisteredInBackend);
350  }
351 
356  {
357  $subject = $this->‪setUpSubject();
358  $redis = $this->‪setUpRedis();
359  $identifier = ‪StringUtility::getUniqueId('identifier');
360  $subject->set($identifier, 'data', ['tag']);
361  self::assertSame(\Redis::REDIS_SET, $redis->type('identTags:' . $identifier));
362  }
363 
368  {
369  $subject = $this->‪setUpSubject();
370  $redis = $this->‪setUpRedis();
371  $identifier = ‪StringUtility::getUniqueId('identifier');
372  $tags = ['thatTag', 'thisTag'];
373  $subject->set($identifier, 'data', $tags);
374  $savedTags = $redis->sMembers('identTags:' . $identifier);
375  sort($savedTags);
376  self::assertSame($tags, $savedTags);
377  }
378 
383  {
384  $subject = $this->‪setUpSubject();
385  $redis = $this->‪setUpRedis();
386  $identifier = ‪StringUtility::getUniqueId('identifier');
387  $tags = ['fooTag', 'barTag'];
388  $subject->set($identifier, 'data', $tags);
389  $subject->set($identifier, 'data', []);
390  self::assertSame([], $redis->sMembers('identTags:' . $identifier));
391  }
392 
397  {
398  $subject = $this->‪setUpSubject();
399  $redis = $this->‪setUpRedis();
400  $identifier = ‪StringUtility::getUniqueId('identifier');
401  $firstTagSet = ['tag1', 'tag2', 'tag3', 'tag4'];
402  $subject->set($identifier, 'data', $firstTagSet);
403  $secondTagSet = ['tag1', 'tag3'];
404  $subject->set($identifier, 'data', $secondTagSet);
405  $actualTagSet = $redis->sMembers('identTags:' . $identifier);
406  sort($actualTagSet);
407  self::assertSame($secondTagSet, $actualTagSet);
408  }
409 
414  {
415  $subject = $this->‪setUpSubject();
416  $redis = $this->‪setUpRedis();
417  $identifier = ‪StringUtility::getUniqueId('identifier');
418  $tag = 'tag';
419  $subject->set($identifier, 'data', [$tag]);
420  self::assertSame(\Redis::REDIS_SET, $redis->type('tagIdents:' . $tag));
421  }
422 
427  {
428  $subject = $this->‪setUpSubject();
429  $redis = $this->‪setUpRedis();
430  $identifier = ‪StringUtility::getUniqueId('identifier');
431  $tag = 'thisTag';
432  $subject->set($identifier, 'data', [$tag]);
433  $savedTagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
434  self::assertSame([$identifier], $savedTagToIdentifiersMemberArray);
435  }
436 
441  {
442  $subject = $this->‪setUpSubject();
443  $redis = $this->‪setUpRedis();
444  $firstIdentifier = ‪StringUtility::getUniqueId('identifier1-');
445  $tag = 'thisTag';
446  $subject->set($firstIdentifier, 'data', [$tag]);
447  $secondIdentifier = ‪StringUtility::getUniqueId('identifier2-');
448  $subject->set($secondIdentifier, 'data', [$tag]);
449  $savedTagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
450  sort($savedTagToIdentifiersMemberArray);
451  $identifierArray = [$firstIdentifier, $secondIdentifier];
452  sort($identifierArray);
453  self::assertSame([$firstIdentifier, $secondIdentifier], $savedTagToIdentifiersMemberArray);
454  }
455 
460  {
461  $subject = $this->‪setUpSubject();
462  $redis = $this->‪setUpRedis();
463  $identifier = ‪StringUtility::getUniqueId('identifier');
464  $tag = 'thisTag';
465  $subject->set($identifier, 'data', [$tag]);
466  $subject->set($identifier, 'data', []);
467  $savedTagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
468  self::assertSame([], $savedTagToIdentifiersMemberArray);
469  }
470 
475  {
476  $subject = $this->‪setUpSubject();
477  $redis = $this->‪setUpRedis();
478  $identifier = ‪StringUtility::getUniqueId('identifier');
479  $subject->set($identifier, 'data');
480  $tag = 'thisTag';
481  $subject->set($identifier, 'data', [$tag]);
482  $savedTagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
483  self::assertSame([$identifier], $savedTagToIdentifiersMemberArray);
484  }
485 
490  {
491  $subject = $this->‪setUpSubject([
492  'compression' => true
493  ]);
494  $redis = $this->‪setUpRedis();
495  $identifier = ‪StringUtility::getUniqueId('identifier');
496  $data = 'some data ' . microtime();
497  $subject->set($identifier, $data);
498  $uncompressedStoredData = '';
499  try {
500  $uncompressedStoredData = @gzuncompress($redis->get('identData:' . $identifier));
501  } catch (\‪Exception $e) {
502  }
503  self::assertEquals($data, $uncompressedStoredData, 'Original and compressed data don\'t match');
504  }
505 
510  {
511  $subject = $this->‪setUpSubject([
512  'compression' => true,
513  'compressionLevel' => 0
514  ]);
515  $redis = $this->‪setUpRedis();
516  $identifier = ‪StringUtility::getUniqueId('identifier');
517  $data = 'some data ' . microtime();
518  $subject->set($identifier, $data);
519  self::assertGreaterThan(0, substr_count($redis->get('identData:' . $identifier), $data), 'Plaintext data not found');
520  }
521 
526  {
527  $this->expectException(\InvalidArgumentException::class);
528  $this->expectExceptionCode(1377006653);
529 
530  $subject = $this->‪setUpSubject();
531  $subject->has([]);
532  }
533 
538  {
539  $subject = $this->‪setUpSubject();
540  $identifier = ‪StringUtility::getUniqueId('identifier');
541  self::assertFalse($subject->has($identifier));
542  }
543 
548  {
549  $subject = $this->‪setUpSubject();
550  $identifier = ‪StringUtility::getUniqueId('identifier');
551  $subject->set($identifier, 'data');
552  self::assertTrue($subject->has($identifier));
553  }
554 
559  {
560  $this->expectException(\InvalidArgumentException::class);
561  // @todo Add exception code with redis extension
562 
563  $subject = $this->‪setUpSubject();
564  $subject->get([]);
565  }
566 
571  {
572  $subject = $this->‪setUpSubject([
573  'compression' => true
574  ]);
575  $data = 'data';
576  $identifier = ‪StringUtility::getUniqueId('identifier');
577  $subject->set($identifier, $data);
578  $fetchedData = $subject->get($identifier);
579  self::assertSame($data, $fetchedData);
580  }
581 
586  {
587  $subject = $this->‪setUpSubject();
588  $data = 'data';
589  $identifier = ‪StringUtility::getUniqueId('identifier');
590  $subject->set($identifier, $data);
591  $fetchedData = $subject->get($identifier);
592  self::assertSame($data, $fetchedData);
593  }
594 
599  {
600  $this->expectException(\InvalidArgumentException::class);
601  $this->expectExceptionCode(1377006654);
602 
603  $subject = $this->‪setUpSubject();
604  $subject->remove([]);
605  }
606 
611  {
612  $subject = $this->‪setUpSubject();
613  self::assertFalse($subject->remove(‪StringUtility::getUniqueId('identifier')));
614  }
615 
620  {
621  $subject = $this->‪setUpSubject();
622  $identifier = ‪StringUtility::getUniqueId('identifier');
623  $subject->set($identifier, 'data');
624  self::assertTrue($subject->remove($identifier));
625  }
626 
631  {
632  $subject = $this->‪setUpSubject();
633  $identifier = ‪StringUtility::getUniqueId('identifier');
634  $subject->set($identifier, 'data');
635  $subject->remove($identifier);
636  self::assertFalse($subject->has($identifier));
637  }
638 
643  {
644  $subject = $this->‪setUpSubject();
645  $redis = $this->‪setUpRedis();
646  $identifier = ‪StringUtility::getUniqueId('identifier');
647  $tag = 'thisTag';
648  $subject->set($identifier, 'data', [$tag]);
649  $subject->remove($identifier);
650  $result = $redis->exists('identTags:' . $identifier);
651  if (is_int($result)) {
652  // Since 3.1.4 of phpredis/phpredis the return types has been changed
653  $result = (bool)$result;
654  }
655  self::assertFalse($result);
656  }
657 
662  {
663  $subject = $this->‪setUpSubject();
664  $redis = $this->‪setUpRedis();
665  $identifier = ‪StringUtility::getUniqueId('identifier');
666  $tag = 'thisTag';
667  $subject->set($identifier, 'data', [$tag]);
668  $subject->remove($identifier);
669  $tagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
670  self::assertSame([], $tagToIdentifiersMemberArray);
671  }
672 
677  {
678  $subject = $this->‪setUpSubject();
679  $redis = $this->‪setUpRedis();
680  $firstIdentifier = ‪StringUtility::getUniqueId('identifier');
681  $secondIdentifier = ‪StringUtility::getUniqueId('identifier');
682  $tag = 'thisTag';
683  $subject->set($firstIdentifier, 'data', [$tag]);
684  $subject->set($secondIdentifier, 'data', [$tag]);
685  $subject->remove($firstIdentifier);
686  $tagToIdentifiersMemberArray = $redis->sMembers('tagIdents:' . $tag);
687  self::assertSame([$secondIdentifier], $tagToIdentifiersMemberArray);
688  }
689 
694  {
695  $this->expectException(\InvalidArgumentException::class);
696  $this->expectExceptionCode(1377006655);
697 
698  $subject = $this->‪setUpSubject();
699  $subject->findIdentifiersByTag([]);
700  }
701 
706  {
707  $subject = $this->‪setUpSubject();
708  self::assertSame([], $subject->findIdentifiersByTag('thisTag'));
709  }
710 
715  {
716  $subject = $this->‪setUpSubject();
717  $firstIdentifier = ‪StringUtility::getUniqueId('identifier1-');
718  $secondIdentifier = ‪StringUtility::getUniqueId('identifier2-');
719  $thirdIdentifier = ‪StringUtility::getUniqueId('identifier3-');
720  $tagsForFirstIdentifier = ['thisTag'];
721  $tagsForSecondIdentifier = ['thatTag'];
722  $tagsForThirdIdentifier = ['thisTag', 'thatTag'];
723  $subject->set($firstIdentifier, 'data', $tagsForFirstIdentifier);
724  $subject->set($secondIdentifier, 'data', $tagsForSecondIdentifier);
725  $subject->set($thirdIdentifier, 'data', $tagsForThirdIdentifier);
726  $expectedResult = [$firstIdentifier, $thirdIdentifier];
727  $actualResult = $subject->findIdentifiersByTag('thisTag');
728  sort($actualResult);
729  self::assertSame($expectedResult, $actualResult);
730  }
731 
736  {
737  $subject = $this->‪setUpSubject();
738  $redis = $this->‪setUpRedis();
739  $identifier = ‪StringUtility::getUniqueId('identifier');
740  $subject->set($identifier, 'data');
741  $subject->flush();
742  self::assertSame([], $redis->getKeys('*'));
743  }
744 
749  {
750  $this->expectException(\InvalidArgumentException::class);
751  $this->expectExceptionCode(1377006656);
752 
753  $subject = $this->‪setUpSubject();
754  $subject->flushByTag([]);
755  }
756 
761  {
762  $subject = $this->‪setUpSubject();
763  $identifier = ‪StringUtility::getUniqueId('identifier');
764  $subject->set($identifier . 'A', 'data', ['tag1']);
765  $subject->set($identifier . 'B', 'data', ['tag2']);
766  $subject->set($identifier . 'C', 'data', ['tag1', 'tag2']);
767  $subject->flushByTag('tag1');
768  $expectedResult = [false, true, false];
769  $actualResult = [
770  $subject->has($identifier . 'A'),
771  $subject->has($identifier . 'B'),
772  $subject->has($identifier . 'C')
773  ];
774  self::assertSame($expectedResult, $actualResult);
775  }
776 
781  {
782  $subject = $this->‪setUpSubject();
783  $identifier = ‪StringUtility::getUniqueId('identifier');
784  $subject->set($identifier . 'A', 'data', ['tag1']);
785  $subject->set($identifier . 'B', 'data', ['tag2']);
786  $subject->set($identifier . 'C', 'data', ['tag1', 'tag2']);
787  $subject->set($identifier . 'D', 'data', ['tag3']);
788  $subject->flushByTags(['tag1', 'tag2']);
789  $expectedResult = [false, false, false, true];
790  $actualResult = [
791  $subject->has($identifier . 'A'),
792  $subject->has($identifier . 'B'),
793  $subject->has($identifier . 'C'),
794  $subject->has($identifier . 'D')
795  ];
796  self::assertSame($expectedResult, $actualResult);
797  }
798 
803  {
804  $subject = $this->‪setUpSubject();
805  $redis = $this->‪setUpRedis();
806  $identifier = ‪StringUtility::getUniqueId('identifier');
807  $subject->set($identifier . 'A', 'data', ['tag1']);
808  $subject->set($identifier . 'C', 'data', ['tag1', 'tag2']);
809  $subject->flushByTag('tag1');
810  self::assertSame([], $redis->getKeys('temp*'));
811  }
812 
817  {
818  $subject = $this->‪setUpSubject();
819  $redis = $this->‪setUpRedis();
820  $identifier = ‪StringUtility::getUniqueId('identifier');
821  $tag = 'tag1';
822  $subject->set($identifier, 'data', [$tag]);
823  $subject->flushByTag($tag);
824  $result = $redis->exists('identTags:' . $identifier);
825  if (is_int($result)) {
826  // Since 3.1.4 of phpredis/phpredis the return types has been changed
827  $result = (bool)$result;
828  }
829  self::assertFalse($result);
830  }
831 
836  {
837  $subject = $this->‪setUpSubject();
838  $redis = $this->‪setUpRedis();
839  $identifierToBeRemoved = ‪StringUtility::getUniqueId('identifier');
840  $tagToRemove = 'tag1';
841  $subject->set($identifierToBeRemoved, 'data', [$tagToRemove]);
842  $identifierNotToBeRemoved = ‪StringUtility::getUniqueId('identifier');
843  $tagNotToRemove = 'tag2';
844  $subject->set($identifierNotToBeRemoved, 'data', [$tagNotToRemove]);
845  $subject->flushByTag($tagToRemove);
846  self::assertSame([$tagNotToRemove], $redis->sMembers('identTags:' . $identifierNotToBeRemoved));
847  }
848 
853  {
854  $subject = $this->‪setUpSubject();
855  $redis = $this->‪setUpRedis();
856  $identifier = ‪StringUtility::getUniqueId('identifier');
857  $tag = 'tag1';
858  $subject->set($identifier, 'data', [$tag]);
859  $subject->flushByTag($tag);
860  $result = $redis->exists('tagIdents:' . $tag);
861  if (is_int($result)) {
862  // Since 3.1.4 of phpredis/phpredis the return types has been changed
863  $result = (bool)$result;
864  }
865  self::assertFalse($result);
866  }
867 
872  {
873  $subject = $this->‪setUpSubject();
874  $redis = $this->‪setUpRedis();
875  $identifier = ‪StringUtility::getUniqueId('identifier');
876  $subject->set($identifier . 'A', 'data', ['tag1', 'tag2']);
877  $subject->set($identifier . 'B', 'data', ['tag1', 'tag2']);
878  $subject->set($identifier . 'C', 'data', ['tag2']);
879  $subject->flushByTag('tag1');
880  self::assertSame([$identifier . 'C'], $redis->sMembers('tagIdents:tag2'));
881  }
882 
887  {
888  $subject = $this->‪setUpSubject();
889  $redis = $this->‪setUpRedis();
890  $identifier = ‪StringUtility::getUniqueId('identifier');
891  $subject->set($identifier . 'A', 'data', ['tag']);
892  $subject->set($identifier . 'B', 'data', ['tag']);
893  $redis->del('identData:' . $identifier . 'A');
894  $subject->collectGarbage();
895  $result = $redis->exists('identData:' . $identifier . 'B');
896  if (is_int($result)) {
897  // Since 3.1.4 of phpredis/phpredis the return types has been changed
898  $result = (bool)$result;
899  }
900  self::assertTrue($result);
901  }
902 
907  {
908  $subject = $this->‪setUpSubject();
909  $redis = $this->‪setUpRedis();
910  $identifier = ‪StringUtility::getUniqueId('identifier');
911  $subject->set($identifier . 'A', 'data', ['tag']);
912  $subject->set($identifier . 'B', 'data', ['tag']);
913  $redis->del('identData:' . $identifier . 'A');
914  $subject->collectGarbage();
915  $expectedResult = [false, true];
916  $resultA = $redis->exists('identTags:' . $identifier . 'A');
917  $resultB = $redis->exists('identTags:' . $identifier . 'B');
918  if (is_int($resultA)) {
919  // Since 3.1.4 of phpredis/phpredis the return types has been changed
920  $resultA = (bool)$resultA;
921  }
922  if (is_int($resultB)) {
923  // Since 3.1.4 of phpredis/phpredis the return types has been changed
924  $resultB = (bool)$resultB;
925  }
926  $actualResult = [
927  $resultA,
928  $resultB
929  ];
930  self::assertSame($expectedResult, $actualResult);
931  }
932 
937  {
938  $subject = $this->‪setUpSubject();
939  $redis = $this->‪setUpRedis();
940  $identifier = ‪StringUtility::getUniqueId('identifier');
941  $subject->set($identifier . 'A', 'data', ['tag1', 'tag2']);
942  $subject->set($identifier . 'B', 'data', ['tag2']);
943  $redis->del('identData:' . $identifier . 'A');
944  $subject->collectGarbage();
945  $expectedResult = [
946  [],
947  [$identifier . 'B']
948  ];
949  $actualResult = [
950  $redis->sMembers('tagIdents:tag1'),
951  $redis->sMembers('tagIdents:tag2')
952  ];
953  self::assertSame($expectedResult, $actualResult);
954  }
955 }
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setUpRedis
‪setUpRedis()
Definition: RedisBackendTest.php:77
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setOverwritesExistingEntryWithNewDefaultLifetime
‪setOverwritesExistingEntryWithNewDefaultLifetime()
Definition: RedisBackendTest.php:321
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\findIdentifiersByTagReturnsAllIdentifiersTagedWithSpecifiedTag
‪findIdentifiersByTagReturnsAllIdentifiersTagedWithSpecifiedTag()
Definition: RedisBackendTest.php:714
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\getReturnsPreviouslySetEntry
‪getReturnsPreviouslySetEntry()
Definition: RedisBackendTest.php:585
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeReturnsTrueIfAnEntryWasDeleted
‪removeReturnsTrueIfAnEntryWasDeleted()
Definition: RedisBackendTest.php:619
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesEntryWithUnlimitedLifeTime
‪setSavesEntryWithUnlimitedLifeTime()
Definition: RedisBackendTest.php:277
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setDatabaseThrowsExceptionIfGivenDatabaseNumberIsNotAnInteger
‪setDatabaseThrowsExceptionIfGivenDatabaseNumberIsNotAnInteger()
Definition: RedisBackendTest.php:93
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend
Definition: MemcachedBackendTest.php:16
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\collectGarbageRemovesExpiredIdentifierFromTagsToIdentifierSet
‪collectGarbageRemovesExpiredIdentifierFromTagsToIdentifierSet()
Definition: RedisBackendTest.php:936
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesEntryWithSpecifiedLifeTime
‪setSavesEntryWithSpecifiedLifeTime()
Definition: RedisBackendTest.php:263
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setCompressionLevelThrowsExceptionIfCompressionLevelIsNotBetweenMinusOneAndNine
‪setCompressionLevelThrowsExceptionIfCompressionLevelIsNotBetweenMinusOneAndNine()
Definition: RedisBackendTest.php:137
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeReturnsFalseIfNoEntryWasDeleted
‪removeReturnsFalseIfNoEntryWasDeleted()
Definition: RedisBackendTest.php:610
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setStoresEntriesInSelectedDatabase
‪setStoresEntriesInSelectedDatabase()
Definition: RedisBackendTest.php:218
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\collectGarbageRemovesLeftOverIdentifierToTagsSet
‪collectGarbageRemovesLeftOverIdentifierToTagsSet()
Definition: RedisBackendTest.php:906
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\getReturnsPreviouslyCompressedSetEntry
‪getReturnsPreviouslyCompressedSetEntry()
Definition: RedisBackendTest.php:570
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setDatabaseThrowsExceptionIfGivenDatabaseNumberIsNegative
‪setDatabaseThrowsExceptionIfGivenDatabaseNumberIsNegative()
Definition: RedisBackendTest.php:104
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setOverwritesExistingEntryWithSpecifiedLifetime
‪setOverwritesExistingEntryWithSpecifiedLifetime()
Definition: RedisBackendTest.php:305
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setOverwritesExistingEntryWithNewData
‪setOverwritesExistingEntryWithNewData()
Definition: RedisBackendTest.php:290
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagRemovesTemporarySet
‪flushByTagRemovesTemporarySet()
Definition: RedisBackendTest.php:802
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeDeletesIdentifierFromTagToIdentifiersSetWithMultipleEntries
‪removeDeletesIdentifierFromTagToIdentifiersSetWithMultipleEntries()
Definition: RedisBackendTest.php:676
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagRemovesTagToIdentifiersSetOfGivenTag
‪flushByTagRemovesTagToIdentifiersSetOfGivenTag()
Definition: RedisBackendTest.php:852
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setThrowsExceptionIfIdentifierIsNotAString
‪setThrowsExceptionIfIdentifierIsNotAString()
Definition: RedisBackendTest.php:170
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\hasThrowsExceptionIfIdentifierIsNotAString
‪hasThrowsExceptionIfIdentifierIsNotAString()
Definition: RedisBackendTest.php:525
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesIdentifierInTagToIdentifiersSetOfSpecifiedTag
‪setSavesIdentifierInTagToIdentifiersSetOfSpecifiedTag()
Definition: RedisBackendTest.php:426
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagDoesNotRemoveIdentifierToTagsSetOfUnrelatedEntry
‪flushByTagDoesNotRemoveIdentifierToTagsSetOfUnrelatedEntry()
Definition: RedisBackendTest.php:835
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setUpSubject
‪setUpSubject(array $backendOptions=[])
Definition: RedisBackendTest.php:54
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\collectGarbageDoesNotRemoveNotExpiredIdentifierToDataEntry
‪collectGarbageDoesNotRemoveNotExpiredIdentifierToDataEntry()
Definition: RedisBackendTest.php:886
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setCompressionThrowsExceptionIfCompressionParameterIsNotOfTypeBoolean
‪setCompressionThrowsExceptionIfCompressionParameterIsNotOfTypeBoolean()
Definition: RedisBackendTest.php:115
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setAppendsSecondIdentifierInTagToIdentifiersEntry
‪setAppendsSecondIdentifierInTagToIdentifiersEntry()
Definition: RedisBackendTest.php:440
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeDeletesEntryFromCache
‪removeDeletesEntryFromCache()
Definition: RedisBackendTest.php:630
‪TYPO3\CMS\Core\Cache\Backend\RedisBackend
Definition: RedisBackend.php:31
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesSetDataTypeForIdentifierToTagsSet
‪setSavesSetDataTypeForIdentifierToTagsSet()
Definition: RedisBackendTest.php:355
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\hasReturnsFalseForNotExistingEntry
‪hasReturnsFalseForNotExistingEntry()
Definition: RedisBackendTest.php:537
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\hasReturnsTrueForPreviouslySetEntry
‪hasReturnsTrueForPreviouslySetEntry()
Definition: RedisBackendTest.php:547
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagsRemovesEntriesTaggedWithSpecifiedTags
‪flushByTagsRemovesEntriesTaggedWithSpecifiedTags()
Definition: RedisBackendTest.php:780
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeDeletesIdentifierFromTagToIdentifiersSet
‪removeDeletesIdentifierFromTagToIdentifiersSet()
Definition: RedisBackendTest.php:661
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setOverwritesExistingEntryWithNewUnlimitedLifetime
‪setOverwritesExistingEntryWithNewUnlimitedLifetime()
Definition: RedisBackendTest.php:339
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setRemovesIdentifierFromTagToIdentifiersEntryIfTagIsOmittedOnConsecutiveSet
‪setRemovesIdentifierFromTagToIdentifiersEntryIfTagIsOmittedOnConsecutiveSet()
Definition: RedisBackendTest.php:459
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagThrowsExceptionIfTagIsNotAString
‪flushByTagThrowsExceptionIfTagIsNotAString()
Definition: RedisBackendTest.php:748
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesStringDataTypeForIdentifierToDataEntry
‪setSavesStringDataTypeForIdentifierToDataEntry()
Definition: RedisBackendTest.php:236
‪TYPO3\CMS\Core\Cache\Exception\InvalidDataException
Definition: InvalidDataException.php:24
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesPlaintextDataWithEnabledCompressionAndCompressionLevel0
‪setSavesPlaintextDataWithEnabledCompressionAndCompressionLevel0()
Definition: RedisBackendTest.php:509
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setRemovesAllPreviouslySetTagsFromIdentifierToTagsSet
‪setRemovesAllPreviouslySetTagsFromIdentifierToTagsSet()
Definition: RedisBackendTest.php:382
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesSetDataTypeForTagToIdentifiersSet
‪setSavesSetDataTypeForTagToIdentifiersSet()
Definition: RedisBackendTest.php:413
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setThrowsExceptionIfLifetimeIsNegative
‪setThrowsExceptionIfLifetimeIsNegative()
Definition: RedisBackendTest.php:194
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagRemovesIdentifierToTagsSetOfEntryTaggedWithGivenTag
‪flushByTagRemovesIdentifierToTagsSetOfEntryTaggedWithGivenTag()
Definition: RedisBackendTest.php:816
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagRemovesEntriesTaggedWithSpecifiedTag
‪flushByTagRemovesEntriesTaggedWithSpecifiedTag()
Definition: RedisBackendTest.php:760
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeDeletesIdentifierToTagEntry
‪removeDeletesIdentifierToTagEntry()
Definition: RedisBackendTest.php:642
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesEntryWithDefaultLifeTime
‪setSavesEntryWithDefaultLifeTime()
Definition: RedisBackendTest.php:248
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setUp
‪setUp()
Definition: RedisBackendTest.php:39
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setThrowsExceptionIfDataIsNotAString
‪setThrowsExceptionIfDataIsNotAString()
Definition: RedisBackendTest.php:182
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushRemovesAllEntriesFromCache
‪flushRemovesAllEntriesFromCache()
Definition: RedisBackendTest.php:735
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\findIdentifiersByTagReturnsEmptyArrayForNotExistingTag
‪findIdentifiersByTagReturnsEmptyArrayForNotExistingTag()
Definition: RedisBackendTest.php:705
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\removeThrowsExceptionIfIdentifierIsNotAString
‪removeThrowsExceptionIfIdentifierIsNotAString()
Definition: RedisBackendTest.php:598
‪$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:558
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setRemovesMultiplePreviouslySetTagsFromIdentifierToTagsSet
‪setRemovesMultiplePreviouslySetTagsFromIdentifierToTagsSet()
Definition: RedisBackendTest.php:396
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesSpecifiedTagsInIdentifierToTagsSet
‪setSavesSpecifiedTagsInIdentifierToTagsSet()
Definition: RedisBackendTest.php:367
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setCompressionLevelThrowsExceptionIfCompressionLevelIsNotInteger
‪setCompressionLevelThrowsExceptionIfCompressionLevelIsNotInteger()
Definition: RedisBackendTest.php:126
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setAddsIdentifierInTagToIdentifiersEntryIfTagIsAddedOnConsecutiveSet
‪setAddsIdentifierInTagToIdentifiersEntryIfTagIsAddedOnConsecutiveSet()
Definition: RedisBackendTest.php:474
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest
Definition: RedisBackendTest.php:35
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setConnectionTimeoutThrowsExceptionIfConnectionTimeoutIsNotInteger
‪setConnectionTimeoutThrowsExceptionIfConnectionTimeoutIsNotInteger()
Definition: RedisBackendTest.php:148
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\flushByTagRemovesIdentifiersTaggedWithGivenTagFromTagToIdentifiersSets
‪flushByTagRemovesIdentifiersTaggedWithGivenTagFromTagToIdentifiersSets()
Definition: RedisBackendTest.php:871
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setSavesCompressedDataWithEnabledCompression
‪setSavesCompressedDataWithEnabledCompression()
Definition: RedisBackendTest.php:489
‪TYPO3\CMS\Core\Cache\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setConnectionTimeoutThrowsExceptionIfConnectionTimeoutIsNegative
‪setConnectionTimeoutThrowsExceptionIfConnectionTimeoutIsNegative()
Definition: RedisBackendTest.php:159
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\setThrowsExceptionIfLifetimeIsNotNullOrAnInteger
‪setThrowsExceptionIfLifetimeIsNotNullOrAnInteger()
Definition: RedisBackendTest.php:206
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\RedisBackendTest\findIdentifiersByTagThrowsExceptionIfTagIsNotAString
‪findIdentifiersByTagThrowsExceptionIfTagIsNotAString()
Definition: RedisBackendTest.php:693