phalcon icon indicating copy to clipboard operation
phalcon copied to clipboard

Support Redis Cluster

Open ph4r5h4d opened this issue 10 years ago • 13 comments

Hi As you know as of Redis 3 , this system support clustering and sharding in a way that a system can have redundant session and cache backend .

I checked Zephir codes of Redis backend cache and noticed Phalcon calls it using new Redis(); new version of phpredis (Redis php driver) now supports clustering and array (not sure when they've added Redis array support but Redis cluster support is somehow new ) but they can't be called using normal new Redis() method and need to be called like these :

$obj_cluster = new RedisCluster(NULL, Array('host:7000', 'host:7001', 'host:7003')); $ra = new RedisArray(array("host1", "host2:63792", "host2:6380"));

This way we will have HA redis cluster for backend cache and session (BTW the driver now supports session clustering and it can be done using php.ini , not tested by myself but i'll test it soon)

So it would be great if we can take advantage of Redis Cluster and Redist array natively in Phalcon .

ph4r5h4d avatar Jul 17 '15 19:07 ph4r5h4d

:+1:

sergeyklay avatar Jul 24 '15 08:07 sergeyklay

Any progress?

smdevdk avatar Jan 25 '16 00:01 smdevdk

+1

lubberscorrado avatar Feb 09 '16 13:02 lubberscorrado

+1

jm85martins avatar Mar 17 '16 10:03 jm85martins

+1

srveiga avatar Mar 17 '16 11:03 srveiga

It this feature already in some roadmap?

AndrejJanoga avatar Feb 14 '17 13:02 AndrejJanoga

I guess not.

Jurigag avatar Feb 14 '17 13:02 Jurigag

I don't want to sound rude, but technically, it's a blocker and still unresolved. If you want to use Phalcon with Redis for bigger project, you must to use Redis Cluster (because failover, HA, etc.).

AndrejJanoga avatar Feb 14 '17 13:02 AndrejJanoga

You can always do PR, feel free to do it.

Jurigag avatar Feb 14 '17 13:02 Jurigag

This is definitely not a long term solution, but if you have PHPRedis configured to handle sessions with RedisCluster then you can cheat a little by leveraging the abstract class Phalcon\Session\Adapter since it uses the superglobal $_SESSION. I was able to create a class that extends it and let PHPRedis automatically handle session handling. For example, I created:

<?php
class RedisClusterSession extends Phalcon\Session\Adapter
{
}

Then in index.php:

// Setup the session component
$di->setShared('session', function () {
        $session = new RedisClusterSession();
        $session->start();
        return $session;
});

jesseforrest avatar Mar 22 '17 00:03 jesseforrest

Closing in favor of phalcon/cphalcon#13855. Will revisit if the community votes for it, or in later versions.

niden avatar Feb 23 '19 22:02 niden

I'm considering contributing to this issue. Got off track by missing RedisCluster adapter about... 7 years ago? It's crazy its not yet implemented. Is there a reason you are not implementing this? We don't have volounteers or there is a hidden issue in here?

yergo avatar Apr 08 '24 21:04 yergo

@yergo Lack of knowledge and volunteers. To get this going I will need to study on how the cluster works and then write the implementation.

If you are interested in making an adapter for this, you can try it in the https://phalcon/phalcon repository first with a PHP implementation. Then it would be easy to port it to cphalcon. The Storage classes work just fine for phalcon/phalcon

niden avatar Apr 08 '24 21:04 niden