-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MC-32062: [2.4] Deliver first part of Redis improvements
- Loading branch information
Showing
21 changed files
with
532 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Cache\Backend; | ||
|
||
/** | ||
* Redis wrapper to extend current implementation behaviour. | ||
*/ | ||
class Redis extends \Cm_Cache_Backend_Redis | ||
{ | ||
/** | ||
* Local state of preloaded keys. | ||
* | ||
* @var array | ||
*/ | ||
private $preloadedData = []; | ||
|
||
/** | ||
* Array of keys to be preloaded. | ||
* | ||
* @var array | ||
*/ | ||
private $preloadKeys = []; | ||
|
||
/** | ||
* @param array $options | ||
*/ | ||
public function __construct($options = []) | ||
{ | ||
$this->preloadKeys = $options['preload_keys'] ?? []; | ||
parent::__construct($options); | ||
} | ||
|
||
/** | ||
* Load value with given id from cache | ||
* | ||
* @param string $id Cache id | ||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested | ||
* @return bool|string | ||
*/ | ||
public function load($id, $doNotTestCacheValidity = false) | ||
{ | ||
if (!empty($this->preloadKeys) && empty($this->preloadedData)) { | ||
$redis = $this->_slave ?? $this->_redis; | ||
$redis = $redis->pipeline(); | ||
|
||
foreach ($this->preloadKeys as $key) { | ||
$redis->hGet(self::PREFIX_KEY . $key, self::FIELD_DATA); | ||
} | ||
|
||
$this->preloadedData = array_filter(array_combine($this->preloadKeys, $redis->exec())); | ||
} | ||
|
||
if (isset($this->preloadedData[$id])) { | ||
return $this->_decodeData($this->preloadedData[$id]); | ||
} | ||
|
||
return parent::load($id, $doNotTestCacheValidity); | ||
} | ||
|
||
/** | ||
* Cover errors on save operations, which may occurs when Redis cannot evict keys, which is expected in some cases. | ||
* | ||
* @param string $data | ||
* @param string $id | ||
* @param array $tags | ||
* @param bool $specificLifetime | ||
* @return bool | ||
*/ | ||
public function save($data, $id, $tags = [], $specificLifetime = false) | ||
{ | ||
try { | ||
parent::save($data, $id, $tags, $specificLifetime); | ||
} catch (\Throwable $exception) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.
it does not work with the remote sync cache.
If we have different name in configuration of frontend cache let's say I have
l2
name for for that cache and I want to use it with EAV cacheI set in env.php
but because of this virtual type has
![Selection_235](https://user-images.githubusercontent.com/3192770/101891478-5f078080-3ba2-11eb-9a41-5d23dac060b0.png)
eav
value I should either define a sepparate backend witheav
name or rename my l2 toeav
to be able to work with this cache type