Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ rand = { version = "0.8.5", features = ["small_rng"] }
ahash = "0.8.11"
flexi_logger = { version = "0.29.8", features = ["colors"] }
tokio-stream = { version = "0.1.17", features = ["net"] }
nextcloud-config-parser = "0.13.1"
nextcloud-config-parser = "0.14.0"
url = "2.5.4"
clap = { version = "4.5.26", features = ["derive"] }
sd-notify = { version = "0.4.3", optional = true }
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,17 @@ Note that Nextcloud loads all files matching `*.config.php` in the config direct
file.
You can enable this same behavior by passing the `--glob-config` option.

#####
<details>
<summary>Using a separate redis instance for the push server
</summary>

You can optionally use a different redis instance for communications between the Nextcloud server and the push daemon.

This allows spreading moving the load away from the normal redis usage or use a redis setup more optimized for the specific usage (`PUBSUB` traffic instead of cache storage).

You can configure this by setting the `notify_push_redis` config option in the `config.php` of the Nextcloud server, this accepts the same options as the normal redis configurations.

</details>

<details>
<summary>Connecting to redis over TLS
Expand Down
11 changes: 6 additions & 5 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace OCA\NotifyPush\AppInfo;

use OC\RedisFactory;
use OCA\NotifyPush\Capabilities;
use OCA\NotifyPush\CSPListener;
use OCA\NotifyPush\Listener;
use OCA\NotifyPush\Queue\IQueue;
use OCA\NotifyPush\Queue\NullQueue;
use OCA\NotifyPush\Queue\PushRedisFactory;
use OCA\NotifyPush\Queue\RedisQueue;
use OCP\Activity\IManager;
use OCP\AppFramework\App;
Expand Down Expand Up @@ -41,10 +41,11 @@ public function register(IRegistrationContext $context): void {
$context->registerCapability(Capabilities::class);

$context->registerService(IQueue::class, function (ContainerInterface $c) {
/** @var RedisFactory $redisFactory */
$redisFactory = $c->get(RedisFactory::class);
if ($redisFactory->isAvailable()) {
return new RedisQueue($redisFactory->getInstance());
/** @var PushRedisFactory $factory */
$factory = $c->get(PushRedisFactory::class);
$redis = $factory->getRedis();
if ($redis) {
return new RedisQueue($redis);
} else {
return new NullQueue();
}
Expand Down
102 changes: 102 additions & 0 deletions lib/Queue/PushRedisFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Robin Appelman <robin@icewind.nl>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\NotifyPush\Queue;

use OC\RedisFactory;
use OCP\IConfig;

class PushRedisFactory {
private $instance = null;
private IConfig $config;
private RedisFactory $redisFactory;

public function __construct(
IConfig $config,
RedisFactory $redisFactory,
) {
$this->config = $config;
$this->redisFactory = $redisFactory;
}

/**
* @return \Redis|\RedisCluster|null
* @throws \Exception
*/
public function getRedis() {
if ($this->instance) {
return $this->instance;
}
if ($this->config->getSystemValue('notify_push_redis', []) !== []) {
return $this->getSeparateRedis();
} elseif ($this->redisFactory->isAvailable()) {
return $this->redisFactory->getInstance();
} else {
return null;
}
}

private function getSeparateRedis(): \Redis {
$config = $this->config->getSystemValue('notify_push_redis', []);
$timeout = $config['timeout'] ?? 0.0;
$readTimeout = $config['read_timeout'] ?? 0.0;

$auth = null;
if (isset($config['password']) && (string)$config['password'] !== '') {
if (isset($config['user']) && (string)$config['user'] !== '') {
$auth = [$config['user'], $config['password']];
} else {
$auth = $config['password'];
}
}

$persistent = $this->config->getSystemValue('notify_push_redis.persistent', true);

$redis = new \Redis();

$host = $config['host'] ?? '127.0.0.1';
$port = $config['port'] ?? ($host[0] !== '/' ? 6379 : null);

// Support for older phpredis versions not supporting connectionParameters
if (isset($config['ssl_context'])) {
// Non-clustered redis requires connection parameters to be wrapped inside `stream`
$connectionParameters = [
'stream' => $config['ssl_context']
];
if ($persistent) {
/**
* even though the stubs and documentation don't want you to know this,
* pconnect does have the same $connectionParameters argument connect has
*
* https://github.com/phpredis/phpredis/blob/0264de1824b03fb2d0ad515b4d4ec019cd2dae70/redis.c#L710-L730
*
* @psalm-suppress TooManyArguments
*/
$redis->pconnect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters);
} else {
$redis->connect($host, $port, $timeout, null, 0, $readTimeout, $connectionParameters);
}
} else {
if ($persistent) {
$redis->pconnect($host, $port, $timeout, null, 0, $readTimeout);
} else {
$redis->connect($host, $port, $timeout, null, 0, $readTimeout);
}
}

if ($auth !== null) {
$redis->auth($auth);
}

if (isset($config['dbindex'])) {
$redis->select($config['dbindex']);
}

return $redis;
}
}
2 changes: 1 addition & 1 deletion src/config/nc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(super) fn parse_config_file(
database: Some(config.database.url().parse()?),
database_prefix: Some(config.database_prefix),
nextcloud_url: Some(config.nextcloud_url),
redis: Some(config.redis),
redis: Some(config.notify_push_redis.unwrap_or(config.redis)),
..PartialConfig::default()
})
}
Loading