PHPSocialNetwork / phpfastcache

A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
https://www.phpfastcache.com
MIT License
2.38k stars 452 forks source link

Making use of a custom predis/redis client #598

Closed dol closed 6 years ago

dol commented 6 years ago

Configuration:

PhpFastCache version: 6.* PHP version: PHP 7.0

Issue description:

The predis client can also be used with a Redis cluster/sentinel setup. https://github.com/nrk/predis#cluster The current implementation and also v7 doesn't allow to use more than one server. https://github.com/PHPSocialNetwork/phpfastcache/blob/411cf0ad87a52ab93ae31ba07820111a5ebbf022/src/phpFastCache/Drivers/Predis/Driver.php#L157

To allow all the possible predis settings the configurations parameters need to be passed to the client initialization. In v6 and v7 this is not possible due to a limited set of configuration settings and that are merge with the default settings. One solution could be to pass the raw $parameters and $options to the client initialization inside the driver or the add a new config parameter that allows a already Predis client object. E.g:

<?php
use phpFastCache\CacheManager;

$parameters = ['tcp://10.0.0.1?alias=master', 'tcp://10.0.0.2', 'tcp://10.0.0.3'];
$options    = ['replication' => true];
$predis = new Predis\Client($parameters, $options);

$config = [
    'predis-client' => $predis,
];

$InstanceCache = CacheManager::getInstance('predis', $config);
Geolim4 commented 6 years ago

Hello,

This is a known limitation of the (P)redis driver and won't be done in v6 which is now stable. However this could be eventually studied for the v7.

Cheers, Georges

Geolim4 commented 6 years ago

@dol This should do the job. Test it please, so I can make some automated tests on my side too. Thanks. N.b: This has been only implemented for Predis/Redis clients for now. I will may considerate implementing it to other drivers in the future.

Geolim4 commented 6 years ago

@dol Bump :P

Geolim4 commented 6 years ago

The issue has been fixed, thanks you for your contribution :thumbsup:

Geolim4

dol commented 6 years ago

@Geolim4 Thank you for implementing this. I was able to the implementation and I confirm it's working as excepted.