Skip to content

[Cache] Add \Relay\Cluster support #59857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

dorrogeray
Copy link
Contributor

@dorrogeray dorrogeray commented Feb 25, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues n/a
License MIT

This PR allows usage of the \Relay\Cluster class in RedisAdapter when relay extension is installed in version >= 0.10.0.

Example usage

Creating a connection with auth

Note that \Relay\Cluster will only be used if relay extension is loaded

use Symfony\Component\Cache\Adapter\RedisAdapter;

$relayCluster = RedisAdapter::createConnection(
    'redis:?host[valkey-cluster:6372]&host[valkey-cluster:6373]&host[valkey-cluster:6374]&auth=my-password&redis_cluster=1'
);

$cacheUsingRelayCluster = new RedisAdapter($relayCluster);

Creating tls connection with self-signed certificate for testing in local environment

use Symfony\Component\Cache\Adapter\RedisAdapter;

$relayCluster = RedisAdapter::createConnection(
    'rediss:?host[valkey-cluster:6372]&host[valkey-cluster:6373]&host[valkey-cluster:6374]&redis_cluster=1&relay_cluster_context[stream][verify_peer]=false&relay_cluster_context[stream][verify_peer_name]=false&relay_cluster_context[stream][allow_self_signed]=true&relay_cluster_context[stream][local_cert]=/valkey.crt&relay_cluster_context[stream][local_pk]=/valkey.key&relay_cluster_context[stream][cafile]=/valkey.crt&relay_cluster_context[max-retries]=5&relay_cluster_context[client-tracking]=false'
);

Alternatively if you already have an instance of \Relay\Cluster which you want to use:

use Relay\Cluster;
use Symfony\Component\Cache\Adapter\RedisAdapter;

$relayCluster = new Cluster(
    'my-relay-cluster-client',
    [
        'valkey-cluster-untracked:6372',
        'valkey-cluster-untracked:6373',
        'valkey-cluster-untracked:6374',
    ],
);

$cacheUsingRelayCluster = new RedisAdapter($relayCluster);

With this PR, two connection options have been introduced:

CC: @tillkruss

@dorrogeray
Copy link
Contributor Author

I am not sure what to make of this error:

image

Also not sure how to fix the psalm complaining about the the missing classes.

@tillkruss
Copy link

Nice work!

Did you see #59846?

@alexandre-daubois
Copy link
Member

@dorrogeray You can rebase your PR, the test failure you're facing is unrelated to your PR and has been fixed in #59861.

@OskarStark OskarStark changed the title [Cache] Add \Relay\Cluster support to RedisAdapter [Cache][Redis] Add \Relay\Cluster support Feb 26, 2025
@carsonbot carsonbot changed the title [Cache][Redis] Add \Relay\Cluster support [Cache] [Redis] Add \Relay\Cluster support Feb 26, 2025
@nicolas-grekas
Copy link
Member

Actually, can you do the same in the Lock and Semaphore components please?

@dorrogeray dorrogeray force-pushed the cache-add-relay-cluster-support branch from ddb8ecd to b8bd231 Compare February 26, 2025 17:16
@dorrogeray
Copy link
Contributor Author

Actually, can you do the same in the Lock and Semaphore components please?

I will take a look 👍

@dorrogeray dorrogeray requested a review from jderusse as a code owner February 26, 2025 20:34
@dorrogeray dorrogeray force-pushed the cache-add-relay-cluster-support branch 6 times, most recently from 47ed3e2 to b805823 Compare February 26, 2025 23:47
@dorrogeray
Copy link
Contributor Author

Errors in Windows / x86 / minimal-exts / lowest-php (pull_request) don't seem to be related to this PR, PHP 8.5 is crashing on zend_mm_heap corrupted and it looks like there is nothing I can do about the psalm not recognizing the Relay\Relay and Relay\Cluster classes..

@stof @jderusse I think its ready for review.

@alexandre-daubois alexandre-daubois changed the title [Cache] [Redis] Add \Relay\Cluster support [Cache] Add \Relay\Cluster support Feb 27, 2025
@fabpot fabpot force-pushed the cache-add-relay-cluster-support branch from b805823 to f4a76e0 Compare March 3, 2025 07:55
@fabpot
Copy link
Member

fabpot commented Mar 3, 2025

Thank you @dorrogeray.

@fabpot fabpot closed this Mar 3, 2025
fabpot added a commit that referenced this pull request Mar 3, 2025
This PR was squashed before being merged into the 7.3 branch.

Discussion
----------

[Cache] Add `\Relay\Cluster` support

| Q             | A
| ------------- | ---
| Branch?       | 7.3
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | n/a
| License       | MIT

This PR allows usage of the `\Relay\Cluster` class in `RedisAdapter` when [relay](https://relay.so/) extension is installed in version >= 0.10.0.

## Example usage

### Creating a connection with auth

Note that `\Relay\Cluster` will only be used if `relay` extension is loaded

```php
use Symfony\Component\Cache\Adapter\RedisAdapter;

$relayCluster = RedisAdapter::createConnection(
    'redis:?host[valkey-cluster:6372]&host[valkey-cluster:6373]&host[valkey-cluster:6374]&auth=my-password&redis_cluster=1'
);

$cacheUsingRelayCluster = new RedisAdapter($relayCluster);
```

### Creating tls connection with self-signed certificate for testing in local environment

```php
use Symfony\Component\Cache\Adapter\RedisAdapter;

$relayCluster = RedisAdapter::createConnection(
    'rediss:?host[valkey-cluster:6372]&host[valkey-cluster:6373]&host[valkey-cluster:6374]&redis_cluster=1&relay_cluster_context[stream][verify_peer]=false&relay_cluster_context[stream][verify_peer_name]=false&relay_cluster_context[stream][allow_self_signed]=true&relay_cluster_context[stream][local_cert]=/valkey.crt&relay_cluster_context[stream][local_pk]=/valkey.key&relay_cluster_context[stream][cafile]=/valkey.crt&relay_cluster_context[max-retries]=5&relay_cluster_context[client-tracking]=false'
);
```

### Alternatively if you already have an instance of `\Relay\Cluster` which you want to use:
```php
use Relay\Cluster;
use Symfony\Component\Cache\Adapter\RedisAdapter;

$relayCluster = new Cluster(
    'my-relay-cluster-client',
    [
        'valkey-cluster-untracked:6372',
        'valkey-cluster-untracked:6373',
        'valkey-cluster-untracked:6374',
    ],
);

$cacheUsingRelayCluster = new RedisAdapter($relayCluster);
```

With this PR, two connection options have been introduced:
 - ~~`relay_cluster` which is a boolean indicating whether the user wants to create a `\Relay\Cluster` connection~~ Removed in favor of using `redis_cluster` and the fact that `relay` extension is loaded to choose the `\Relay\Cluster` class
 - `command_timeout` which is consumed by `\Relay\Cluster` and defaults to `0`
 - `relay_cluster_context` which is consumed by `\Relay\Cluster` and allows user to configure options described in cachewerk/relay#161 (comment)

CC: `@tillkruss`

Commits
-------

f4a76e0 [Cache] Add `\Relay\Cluster` support
nicolas-grekas added a commit that referenced this pull request Mar 13, 2025
This PR was merged into the 7.3 branch.

Discussion
----------

[Cache] Code cleanup

| Q             | A
| ------------- | ---
| Branch?       | 7.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Follows #59857 /cc `@dorrogeray` (some changes for the upcoming doc)

Commits
-------

922f5ff [Cache] Code cleanup
@fabpot fabpot mentioned this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants