Redis Laravel 连接 redis 报错

yale · 2021-02-23 14:39:08 · 热度: 338
错误1:MOVED 14315 172.200.0.1:6393
Predis \ Response \ ServerException
MOVED 14315 172.200.0.1:6393

问题原因:需要用集群模式连接 Redis 集群,例如,使用如下配置中的mycluster1连接.

#如果是用 redis-cli -h 172.17.0.1 -p 6379命令连接redis报此错误错,则在命令中加-c参数即可,-c表示用集群模式连接。
redis-cli -c -h 172.17.0.1 -p 6379
错误2:No connections available in the pool
Predis \ ClientException
No connections available in the pool

问题原因:redis 集群连接配置不正确

错误3:Redis connection [mycluster1] not configured.
InvalidArgumentException
Redis connection [mycluster1] not configured.

问题原因:没有名称为mycluster1的集群配置

错误4:No connections left in the pool fo CLUSTER SLOTS
Predis \ ClientException
No connections left in the pool for `CLUSTER SLOTS`
正确的配置示例:
'redis' => [
    'client' => 'predis',
    'default' => [
        'host' => env('REDIS_HOST', '172.17.0.1'),
        'password' => env('REDIS_PASSWORD', null),//无密码要填null
        'port' => env('REDIS_PORT', 6379),
        'database' => 0,
    ],
    'options' => [
        'cluster' => 'redis',
    ],
    'clusters' => [
        //集群1
        'cluster1' => [
            [
                'host' => '172.17.0.1',
                'password' => null,//无密码要填null
                'port' => 6379,
                'database' => 0,
            ],
        ],
        //集群2
        'cluster2' => [
            [
                'host' => '192.168.31.244',
                'password' => null,//无密码要填null
                'port' => 6379,
                'database' => 0,
            ],
        ],
    ],
],
正确的连接示例:
$redis = Redis::connection('cluster1');
$redis->set('username','wdh');
echo $redis->get('username');

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册