Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nelson-ph/e06392a6d6aa465a0768785d055bc5a6 to your computer and use it in GitHub Desktop.
Save nelson-ph/e06392a6d6aa465a0768785d055bc5a6 to your computer and use it in GitHub Desktop.
Drupal 8 - Redis cluster - report controller support
Index: src/Controller/ReportController.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php
--- a/src/Controller/ReportController.php (date 1619714576096)
+++ b/src/Controller/ReportController.php (date 1619714576096)
@@ -9,6 +9,7 @@
use Drupal\redis\ClientFactory;
use Drupal\redis\RedisPrefixTrait;
use Predis\Collection\Iterator\Keyspace;
+use Predis\Connection\Aggregate\ClusterInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -312,7 +313,12 @@
}
}
elseif ($this->redis instanceof \Predis\Client) {
- yield from new Keyspace($this->redis, $match, $count);
+ $client = $this->redis;
+ if ($this->redis->getConnection() instanceof ClusterInterface) {
+ $client = $this->redis->getClientFor(implode(':',
+ [getenv('REDIS_HOST'), getenv('REDIS_PORT')]));
+ }
+ yield from new Keyspace($client, $match, $count);
}
}
@@ -323,11 +329,17 @@
*/
protected function info() {
$normalized_info = [];
+ $client = $this->redis;
if ($this->redis instanceof \RedisCluster) {
- $master = current($this->redis->_masters());
- $info = $this->redis->info($master);
+ $client = current($this->redis->_masters());
+ $info = $this->redis->info($client);
}
- else {
+ if ($this->redis->getConnection() instanceof ClusterInterface) {
+ $client = $this->redis->getClientFor(implode(':',
+ [getenv('REDIS_HOST'), getenv('REDIS_PORT')]));
+ $info = $client->info();
+ }
+ if(empty($info)) {
$info = $this->redis->info();
}
@@ -335,17 +347,25 @@
$normalized_info['redis_mode'] = $info['redis_mode'] ?? $info['Server']['redis_mode'];
$normalized_info['connected_clients'] = $info['connected_clients'] ?? $info['Clients']['connected_clients'];
if ($this->redis instanceof \RedisCluster) {
- $master = current($this->redis->_masters());
- $normalized_info['db_size'] = $this->redis->dbSize($master);
+ $normalized_info['db_size'] = $this->redis->dbSize($client);
}
- else {
+ if ($this->redis->getConnection() instanceof ClusterInterface) {
+ $normalized_info['db_size'] = $client->dbSize();
+ }
+ if(empty($normalized_info['db_size'])) {
$normalized_info['db_size'] = $this->redis->dbSize();
}
$normalized_info['used_memory'] = $info['used_memory'] ?? $info['Memory']['used_memory'];
$normalized_info['used_memory_human'] = $info['used_memory_human'] ?? $info['Memory']['used_memory_human'];
if (empty($info['maxmemory_policy'])) {
- $memory_config = $this->redis->config('get', 'maxmemory*');
+ if ($this->redis->getConnection() instanceof ClusterInterface) {
+ $memory_config = $client->config('get', 'maxmemory*');
+ }
+ else{
+ $memory_config = $this->redis->config('get', 'maxmemory*');
+ }
+
$normalized_info['maxmemory_policy'] = $memory_config['maxmemory-policy'];
$normalized_info['maxmemory'] = $memory_config['maxmemory'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment