monospice / laravel-redis-sentinel-drivers

Redis Sentinel integration for Laravel and Lumen.
MIT License
101 stars 48 forks source link

Compatible with redis cluster #22

Closed L3o-pold closed 5 years ago

L3o-pold commented 5 years ago

Is this package compatible with redis clustering?

I got the following error.

Predis\\Response\\ServerException MOVED 6918 x.x.x.x:6379

Am I missing something?

routes/web.php

use Monospice\LaravelRedisSentinel\RedisSentinel;

Route::get('/ping', function () {
    RedisSentinel::get('test');
});
 "exception": "Predis\\Response\\ServerException",
    "file": "/var/www/html/vendor/predis/predis/src/Client.php",
    "line": 370,
    "trace": [
        {
            "file": "/var/www/html/vendor/predis/predis/src/Client.php",
            "line": 335,
            "function": "onErrorResponse",
            "class": "Predis\\Client",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/predis/predis/src/Client.php",
            "line": 314,
            "function": "executeCommand",
            "class": "Predis\\Client",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php",
            "line": 114,
            "function": "__call",
            "class": "Predis\\Client",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php",
            "line": 214,
            "function": "command",
            "class": "Illuminate\\Redis\\Connections\\Connection",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php",
            "line": 214,
            "function": "__call",
            "class": "Illuminate\\Redis\\Connections\\Connection",
            "type": "->"
        },
        {
            "function": "__call",
            "class": "Illuminate\\Redis\\RedisManager",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/monospice/spicy-identifiers/src/DynamicMethod.php",
            "line": 62,
            "function": "call_user_func_array"
        },
        {
            "file": "/var/www/html/vendor/monospice/laravel-redis-sentinel-drivers/src/RedisSentinelManager.php",
            "line": 96,
            "function": "callOn",
            "class": "Monospice\\SpicyIdentifiers\\DynamicMethod",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php",
            "line": 237,
            "function": "__call",
            "class": "Monospice\\LaravelRedisSentinel\\RedisSentinelManager",
            "type": "->"
        },
REDIS_PASSWORD=null
REDIS_HOST="172.22.0.54"
REDIS_PORT=26379
REDIS_SENTINEL_SERVICE=master
REDIS_SENTINEL_TIMEOUT=10
REDIS_CACHE_DATABASE=1
REDIS_SESSION_DATABASE=2
REDIS_QUEUE_DATABASE=3
CACHE_DRIVER=redis-sentinel
SESSION_DRIVER=redis-sentinel
QUEUE_DRIVER=redis-sentinel
REDIS_DRIVER=redis-sentinel
cyrossignol commented 5 years ago

Hi @L3o-pold, this package targets Redis Sentinel, not Redis Cluster. The terminology is a bit confusing at first.

Sentinel implements a replication strategy that effectively mirrors all the data in one Redis master server to n replicas for high availability and load balancing. If the master server fails, Sentinel promotes one of the replicas to take over. This package abstracts the Sentinel connection protocol so that a Laravel application doesn't need to handle the server selection and fail-over manually.

By contrast, Cluster provides a way to automatically shard a unified dataset between multiple Redis servers to allow for greater storage than one server might hold in memory. We can also configure Cluster for high-availability, but these details are on the Redis side--a Laravel application doesn't need to know about the replication topology like it does with Sentinel.

An application can also manually shard its dataset in a Sentinel setup (via client-side sharding), but there is little benefit to this approach when we have the option to use Redis Cluster. Sentinel is a good choice for applications that benefit from high availability without a great need for storage space. Most Laravel applications fit this use case: the default cache, session, and queue services turn over transient data that doesn't need to be stored for an extended period of time.

Laravel already supports Redis Cluster out-of-the-box. This package enhances the support for Sentinel. If you're using Redis Cluster only, you don't need this package.

L3o-pold commented 5 years ago

Hi @cyrossignol, thank you for your great explanation. You right I was confused about the terminology and intended to used both cluster and sentinel at the same time.