Skip to content
Snippets Groups Projects

Issue #3173988: Azure/AWS: Take into account CONFIG command may not work

Open Eelke Blok requested to merge issue/redis-3173988:3173988-azureaws-take-into into 8.x-1.x
1 file
+ 34
15
Compare changes
  • Side-by-side
  • Inline
@@ -4,9 +4,11 @@ namespace Drupal\redis\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Url;
use Drupal\redis\ClientFactory;
use Drupal\redis\RedisPrefixTrait;
use Exception;
use Predis\Collection\Iterator\Keyspace;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -167,21 +169,38 @@ class ReportController extends ControllerBase {
}
$end = microtime(TRUE);
$memory_config = $this->redis->config('get', 'maxmemory*');
if ($memory_config['maxmemory']) {
$memory_value = $this->t('@used_memory / @max_memory (@used_percentage%), maxmemory policy: @policy', [
'@used_memory' => $info['used_memory_human'] ?? $info['Memory']['used_memory_human'],
'@max_memory' => format_size($memory_config['maxmemory']),
'@used_percentage' => (int) ($info['used_memory'] ?? $info['Memory']['used_memory'] / $memory_config['maxmemory'] * 100),
'@policy' => $memory_config['maxmemory-policy'],
]);
// Various Redis providers may have actually disabled the CONFIG command, so
// try this, but don't be surprised if it fails.
try {
$memory_config = $this->redis->config('get', 'maxmemory*');
if ($memory_config['maxmemory']) {
$memory_value = $this->t('@used_memory / @max_memory (@used_percentage%), maxmemory policy: @policy', [
'@used_memory' => $info['used_memory_human'] ?? $info['Memory']['used_memory_human'],
'@max_memory' => format_size($memory_config['maxmemory']),
'@used_percentage' => (int) ($info['used_memory'] ?? $info['Memory']['used_memory'] / $memory_config['maxmemory'] * 100),
'@policy' => $memory_config['maxmemory-policy'],
]);
}
else {
$memory_value = $this->t('@used_memory / unlimited, maxmemory policy: @policy', [
'@used_memory' => $info['used_memory_human'] ?? $info['Memory']['used_memory_human'],
'@policy' => $memory_config['maxmemory-policy'],
]);
}
}
else {
$memory_value = $this->t('@used_memory / unlimited, maxmemory policy: @policy', [
'@used_memory' => $info['used_memory_human'] ?? $info['Memory']['used_memory_human'],
'@policy' => $memory_config['maxmemory-policy'],
]);
// We can't be sure what sort of Exception will be thrown, depends on the
// integration used.
catch (Exception $e) {
$memory_value = $info['used_memory_human'] ?? $info['Memory']['used_memory_human'];
watchdog_exception(
'redis',
$e,
'Exception caught while trying to retrieve memory configuration from Redis. This may just be a security measure from your Redis provider. %type: @message in %function (line %line of %file).',
[],
RfcLogLevel::INFO);
}
$requirements = [
@@ -248,7 +267,7 @@ class ReportController extends ControllerBase {
];
// Warnings/hints.
if ($memory_config['maxmemory-policy'] == 'noeviction') {
if (isset($memory_config['maxmemory-policy']) && $memory_config['maxmemory-policy'] == 'noeviction') {
$redis_url = Url::fromUri('https://redis.io/topics/lru-cache', [
'fragment' => 'eviction-policies',
'attributes' => [
Loading