Skip to content
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

Support custom native RedisCluster client #906

Closed
mocxi opened this issue Nov 30, 2023 · 9 comments
Closed

Support custom native RedisCluster client #906

mocxi opened this issue Nov 30, 2023 · 9 comments

Comments

@mocxi
Copy link

mocxi commented Nov 30, 2023

What type of feature would you like?

New backend support

The feature request

The current set function new RedisConfig())->setRedisClient($redisClient) only accept Redis object
I'd like to request support RedisCluster so I can set custom native redis cluster client for it

Code sample (optional)

$obj_cluster = new RedisCluster(NULL, Array('host:7000', 'host:7001', 'host:7003'));
$cacheInstance = CacheManager::getInstance('Redis', (new RedisConfig())->setRedisClient($obj_cluster));

References (optional)

https://github.com/phpredis/phpredis/blob/develop/cluster.md

Do you have anything more you want to share? (optional)

I'm using phpfastcache v7

Copy link

Hello curious contributor !
Since it seems to be your first contribution, make sure that you've been:

  • Reading and searching out our WIKI
  • Reading and agreed with our Code Of Conduct
  • Reading and understood our Coding Guideline
  • Reading our README
    If everything looks unclear to you, tell us what 😄
    The Phpfastcache Team

@Geolim4
Copy link
Member

Geolim4 commented Dec 10, 2023

Hello, could be implemented as of 9.2 version as a new feature indeed.

@Geolim4
Copy link
Member

Geolim4 commented Dec 10, 2023

I'm using phpfastcache v7

Just FYI @mocxi, v7 is no longer supported, upgrade at least to v8 for security fixes support or v9 for extended support:

https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV4%CB%96%5D-Global-support-timeline

@Geolim4
Copy link
Member

Geolim4 commented Dec 15, 2023

RedisCluster Class have some different signatures than Redis Class.

So I think that I will may create a new driver that extends the Redis one.

Geolim4 added a commit that referenced this issue Dec 15, 2023
- __API__
  - Upgraded Phpfastcache API to `4.3.0` ([see changes](CHANGELOG_API.md))
- __Drivers__
  - Implemented #906 // **Added `RedisCluster` driver support**
- __Pool__
  - Added `ExtendedCacheItemPoolTrait::getAllItems` to allow you to retrieve all items in the cache. This method have some limitations, ([see more in the Wiki](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV5%CB%96%5D-Fetching-all-keys)).
- __Core__
  - Configuration methods`ConfigurationOption::isPreventCacheSlams()`, `ConfigurationOption::setPreventCacheSlams()`, `ConfigurationOption::getCacheSlamsTimeout()`, `ConfigurationOption::setCacheSlamsTimeout()` are deprecated. ([See changes](CHANGELOG_API.md)).
  - Fixed #907 // Internal "driver decode()" method will now throw an if the string data looks corrupted.
  - Internal: Implemented multiple keys fetch (*if supported by the backend*) to improve the performances behind all `getItems()` calls. Currently only supported in some backends, but it may evolve in the future.
- __Misc__
  - Fixed multiple code typo & updated README.md
Geolim4 added a commit that referenced this issue Dec 15, 2023
- __API__
  - Upgraded Phpfastcache API to `4.3.0` ([see changes](CHANGELOG_API.md))
- __Drivers__
  - Implemented #906 // **Added `RedisCluster` driver support**
- __Pool__
  - Added `ExtendedCacheItemPoolTrait::getAllItems` to allow you to retrieve all items in the cache. This method have some limitations, ([see more in the Wiki](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV5%CB%96%5D-Fetching-all-keys)).
- __Core__
  - Configuration methods`ConfigurationOption::isPreventCacheSlams()`, `ConfigurationOption::setPreventCacheSlams()`, `ConfigurationOption::getCacheSlamsTimeout()`, `ConfigurationOption::setCacheSlamsTimeout()` are deprecated. ([See changes](CHANGELOG_API.md)).
  - Fixed #907 // Internal "driver decode()" method will now throw an if the string data looks corrupted.
  - Internal: Implemented multiple keys fetch (*if supported by the backend*) to improve the performances behind all `getItems()` calls. Currently only supported in some backends, but it may evolve in the future.
- __Misc__
  - Fixed multiple code typo & updated README.md
@Geolim4
Copy link
Member

Geolim4 commented Dec 16, 2023

Can you test the 9.2 dev branch v9.2.x-dev please and telle me if you make it working ?

@Geolim4
Copy link
Member

Geolim4 commented Dec 16, 2023

Syntax:

use Phpfastcache\Drivers\RedisCluster\Config as RedisConfig;
use Phpfastcache\CacheManager;

    $config =  new RedisConfig();
    $config->setClusters( '127.0.0.1:7001', '127.0.0.1:7002', '127.0.0.1:7003', '127.0.0.1:7004', '127.0.0.1:7005', '127.0.0.1:7006');
    $config->setOptPrefix('pfc_');; // optional 
    $config->setSlaveFailover(\RedisCluster::FAILOVER_ERROR); // optional 
    $cacheInstance = CacheManager::getInstance('RedisCluster', $config);

@mocxi
Copy link
Author

mocxi commented Dec 21, 2023

It worked as intended. Thanks for your help!

@mocxi mocxi closed this as completed Dec 21, 2023
@Geolim4
Copy link
Member

Geolim4 commented Dec 21, 2023

Everything looks good for you ? You managed to configure it easily @mocxi ?

Btw 9.2 should be shipped by January.

@mocxi
Copy link
Author

mocxi commented Dec 22, 2023

Yes, I pulled the dev branch, set up a Redis cluster, connected to it and everything is good.
The thing now is I need to upgrade my code base to PHP 8 in order to use the latest 9.x phpfastcache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants