Skip to content

Commit e655dcf

Browse files
committed
feat: add command to send raw commands to redis
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent a184161 commit e655dcf

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2024 Robin Appelman <robin@icewind.nl>
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OC\Core\Command\Memcache;
10+
11+
use OC\Core\Command\Base;
12+
use OC\RedisFactory;
13+
use OCP\ICertificateManager;
14+
use Symfony\Component\Console\Input\InputArgument;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
18+
class RedisCommand extends Base {
19+
public function __construct(
20+
protected ICertificateManager $certificateManager,
21+
protected RedisFactory $redisFactory,
22+
) {
23+
parent::__construct();
24+
}
25+
26+
protected function configure(): void {
27+
$this
28+
->setName('memcache:redis:command')
29+
->setDescription('Send raw redis command to the configured redis server')
30+
->addArgument('redis-command', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'The command to run');
31+
parent::configure();
32+
}
33+
34+
protected function execute(InputInterface $input, OutputInterface $output): int {
35+
$command = $input->getArgument('redis-command');
36+
if (!$this->redisFactory->isAvailable()) {
37+
$output->writeln("<error>No redis server configured</error>");
38+
return 1;
39+
}
40+
try {
41+
$redis = $this->redisFactory->getInstance();
42+
} catch (\Exception $e) {
43+
$output->writeln('Failed to connect to redis: ' . $e->getMessage());
44+
return 1;
45+
}
46+
47+
$redis->setOption(\Redis::OPT_REPLY_LITERAL, true);
48+
$result = $redis->rawCommand(...$command);
49+
if ($result === false) {
50+
$output->writeln("<error>Redis command failed</error>");
51+
return 1;
52+
}
53+
$output->writeln($result);
54+
return 0;
55+
}
56+
}

core/register_command.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@
140140
$application->add(Server::get(Command\Security\BruteforceResetAttempts::class));
141141
$application->add(Server::get(Command\SetupChecks::class));
142142
$application->add(Server::get(Command\FilesMetadata\Get::class));
143+
144+
$application->add(Server::get(Command\Memcache\RedisCommand::class));
143145
} else {
144146
$application->add(Server::get(Command\Maintenance\Install::class));
145147
}

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,7 @@
11491149
'OC\\Core\\Command\\Maintenance\\RepairShareOwnership' => $baseDir . '/core/Command/Maintenance/RepairShareOwnership.php',
11501150
'OC\\Core\\Command\\Maintenance\\UpdateHtaccess' => $baseDir . '/core/Command/Maintenance/UpdateHtaccess.php',
11511151
'OC\\Core\\Command\\Maintenance\\UpdateTheme' => $baseDir . '/core/Command/Maintenance/UpdateTheme.php',
1152+
'OC\\Core\\Command\\Memcache\\RedisCommand' => $baseDir . '/core/Command/Memcache/RedisCommand.php',
11521153
'OC\\Core\\Command\\Preview\\Generate' => $baseDir . '/core/Command/Preview/Generate.php',
11531154
'OC\\Core\\Command\\Preview\\Repair' => $baseDir . '/core/Command/Preview/Repair.php',
11541155
'OC\\Core\\Command\\Preview\\ResetRenderedTexts' => $baseDir . '/core/Command/Preview/ResetRenderedTexts.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
11821182
'OC\\Core\\Command\\Maintenance\\RepairShareOwnership' => __DIR__ . '/../../..' . '/core/Command/Maintenance/RepairShareOwnership.php',
11831183
'OC\\Core\\Command\\Maintenance\\UpdateHtaccess' => __DIR__ . '/../../..' . '/core/Command/Maintenance/UpdateHtaccess.php',
11841184
'OC\\Core\\Command\\Maintenance\\UpdateTheme' => __DIR__ . '/../../..' . '/core/Command/Maintenance/UpdateTheme.php',
1185+
'OC\\Core\\Command\\Memcache\\RedisCommand' => __DIR__ . '/../../..' . '/core/Command/Memcache/RedisCommand.php',
11851186
'OC\\Core\\Command\\Preview\\Generate' => __DIR__ . '/../../..' . '/core/Command/Preview/Generate.php',
11861187
'OC\\Core\\Command\\Preview\\Repair' => __DIR__ . '/../../..' . '/core/Command/Preview/Repair.php',
11871188
'OC\\Core\\Command\\Preview\\ResetRenderedTexts' => __DIR__ . '/../../..' . '/core/Command/Preview/ResetRenderedTexts.php',

0 commit comments

Comments
 (0)