Skip to content

Commit

Permalink
[TASK] Make Redis connectors compatible with PHP redis version 5
Browse files Browse the repository at this point in the history
Version 5 of phpredis deprecates some methods, which have not been
aligned to the official redis commands.
This patch replaces all calls to use the correct methods.

Resolves: #88701
Releases: master, 9.5, 8.7
Change-Id: Ib8921d31a9df6631a99d70fabc8c32f81bbd0fc4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61277
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog <look@susi.dev>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Susanne Moog <look@susi.dev>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
  • Loading branch information
liayn authored and NeoBlack committed Aug 7, 2019
1 parent 35c8bd8 commit f818991
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions typo3/sysext/core/Classes/Cache/Backend/RedisBackend.php
Expand Up @@ -23,8 +23,8 @@
* PHP module. Redis is a noSQL database with very good scaling characteristics
* in proportion to the amount of entries and data size.
*
* @see http://code.google.com/p/redis/
* @see http://github.com/owlient/phpredis
* @see https://redis.io/
* @see https://github.com/phpredis/phpredis
*/
class RedisBackend extends AbstractBackend implements TaggableBackendInterface
{
Expand All @@ -38,7 +38,7 @@ class RedisBackend extends AbstractBackend implements TaggableBackendInterface
* To save these additional calls on every set(),
* we just make every entry volatile and treat a high number as "unlimited"
*
* @see http://code.google.com/p/redis/wiki/ExpireCommand
* @see https://redis.io/commands/expire
* @var int Faked unlimited lifetime
*/
const FAKED_UNLIMITED_LIFETIME = 31536000;
Expand Down Expand Up @@ -334,8 +334,8 @@ public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
if (!empty($removeTags) || !empty($addTags)) {
$queue = $this->redis->multi(\Redis::PIPELINE);
foreach ($removeTags as $tag) {
$queue->sRemove(self::IDENTIFIER_TAGS_PREFIX . $entryIdentifier, $tag);
$queue->sRemove(self::TAG_IDENTIFIERS_PREFIX . $tag, $entryIdentifier);
$queue->sRem(self::IDENTIFIER_TAGS_PREFIX . $entryIdentifier, $tag);
$queue->sRem(self::TAG_IDENTIFIERS_PREFIX . $tag, $entryIdentifier);
}
foreach ($addTags as $tag) {
$queue->sAdd(self::IDENTIFIER_TAGS_PREFIX . $entryIdentifier, $tag);
Expand Down Expand Up @@ -408,9 +408,9 @@ public function remove($entryIdentifier)
$assignedTags = $this->redis->sMembers(self::IDENTIFIER_TAGS_PREFIX . $entryIdentifier);
$queue = $this->redis->multi(\Redis::PIPELINE);
foreach ($assignedTags as $tag) {
$queue->sRemove(self::TAG_IDENTIFIERS_PREFIX . $tag, $entryIdentifier);
$queue->sRem(self::TAG_IDENTIFIERS_PREFIX . $tag, $entryIdentifier);
}
$queue->delete(self::IDENTIFIER_DATA_PREFIX . $entryIdentifier, self::IDENTIFIER_TAGS_PREFIX . $entryIdentifier);
$queue->del(self::IDENTIFIER_DATA_PREFIX . $entryIdentifier, self::IDENTIFIER_TAGS_PREFIX . $entryIdentifier);
$queue->exec();
$elementsDeleted = true;
}
Expand Down Expand Up @@ -485,16 +485,16 @@ public function flushByTag($tag)
*/
public function collectGarbage()
{
$identifierToTagsKeys = $this->redis->getKeys(self::IDENTIFIER_TAGS_PREFIX . '*');
$identifierToTagsKeys = $this->redis->keys(self::IDENTIFIER_TAGS_PREFIX . '*');
foreach ($identifierToTagsKeys as $identifierToTagsKey) {
list(, $identifier) = explode(':', $identifierToTagsKey);
// Check if the data entry still exists
if (!$this->redis->exists(self::IDENTIFIER_DATA_PREFIX . $identifier)) {
$tagsToRemoveIdentifierFrom = $this->redis->sMembers($identifierToTagsKey);
$queue = $this->redis->multi(\Redis::PIPELINE);
$queue->delete($identifierToTagsKey);
$queue->del($identifierToTagsKey);
foreach ($tagsToRemoveIdentifierFrom as $tag) {
$queue->sRemove(self::TAG_IDENTIFIERS_PREFIX . $tag, $identifier);
$queue->sRem(self::TAG_IDENTIFIERS_PREFIX . $tag, $identifier);
}
$queue->exec();
}
Expand Down Expand Up @@ -537,7 +537,7 @@ protected function removeIdentifierEntriesAndRelations(array $identifiers, array
foreach ($tagToIdentifiersSetsToRemoveIdentifiersFrom as $tagToIdentifiersSet) {
$queue->sDiffStore(self::TAG_IDENTIFIERS_PREFIX . $tagToIdentifiersSet, self::TAG_IDENTIFIERS_PREFIX . $tagToIdentifiersSet, $uniqueTempKey);
}
$queue->delete(array_merge($prefixedKeysToDelete, $prefixedIdentifierToTagsKeysToDelete));
$queue->del(array_merge($prefixedKeysToDelete, $prefixedIdentifierToTagsKeysToDelete));
$queue->exec();
}

Expand Down
Expand Up @@ -148,7 +148,7 @@ public function remove(string $sessionId): bool
{
$this->initializeConnection();

return $this->redis->delete($this->getSessionKeyName($sessionId)) >= 1;
return $this->redis->del($this->getSessionKeyName($sessionId)) >= 1;
}

/**
Expand Down Expand Up @@ -224,11 +224,11 @@ public function collectGarbage(int $maximumLifetime, int $maximumAnonymousLifeti
foreach ($this->getAll() as $sessionRecord) {
if ($sessionRecord['ses_anonymous']) {
if ($maximumAnonymousLifetime > 0 && ($sessionRecord['ses_tstamp'] + $maximumAnonymousLifetime) < $GLOBALS['EXEC_TIME']) {
$this->redis->delete($this->getSessionKeyName($sessionRecord['ses_id']));
$this->redis->del($this->getSessionKeyName($sessionRecord['ses_id']));
}
} else {
if (($sessionRecord['ses_tstamp'] + $maximumLifetime) < $GLOBALS['EXEC_TIME']) {
$this->redis->delete($this->getSessionKeyName($sessionRecord['ses_id']));
$this->redis->del($this->getSessionKeyName($sessionRecord['ses_id']));
}
}
}
Expand Down Expand Up @@ -305,7 +305,7 @@ public function getAll(): array
}
}

$encodedSessions = $this->redis->getMultiple($keys);
$encodedSessions = $this->redis->mGet($keys);
if (!is_array($encodedSessions)) {
return [];
}
Expand Down
Expand Up @@ -885,7 +885,7 @@ public function collectGarbageDoesNotRemoveNotExpiredIdentifierToDataEntry()
$identifier = $this->getUniqueId('identifier');
$subject->set($identifier . 'A', 'data', ['tag']);
$subject->set($identifier . 'B', 'data', ['tag']);
$redis->delete('identData:' . $identifier . 'A');
$redis->del('identData:' . $identifier . 'A');
$subject->collectGarbage();
$result = $redis->exists('identData:' . $identifier . 'B');
if (is_int($result)) {
Expand All @@ -905,7 +905,7 @@ public function collectGarbageRemovesLeftOverIdentifierToTagsSet()
$identifier = $this->getUniqueId('identifier');
$subject->set($identifier . 'A', 'data', ['tag']);
$subject->set($identifier . 'B', 'data', ['tag']);
$redis->delete('identData:' . $identifier . 'A');
$redis->del('identData:' . $identifier . 'A');
$subject->collectGarbage();
$expectedResult = [false, true];
$resultA = $redis->exists('identTags:' . $identifier . 'A');
Expand Down Expand Up @@ -935,7 +935,7 @@ public function collectGarbageRemovesExpiredIdentifierFromTagsToIdentifierSet()
$identifier = $this->getUniqueId('identifier');
$subject->set($identifier . 'A', 'data', ['tag1', 'tag2']);
$subject->set($identifier . 'B', 'data', ['tag2']);
$redis->delete('identData:' . $identifier . 'A');
$redis->del('identData:' . $identifier . 'A');
$subject->collectGarbage();
$expectedResult = [
[],
Expand Down

0 comments on commit f818991

Please sign in to comment.