Laravel连接Redis报错

骑猪看日落 2023-07-17 12:37 124阅读 0赞

报错:

错误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 for CLUSTER SLOTS
  • 示例:

    Predis \ ClientException
    No connections left in the pool for CLUSTER SLOTS

正确的使用示例:

配置示例:
  1. 'redis' => [
  2. 'client' => 'predis',
  3. 'default' => [
  4. 'host' => env('REDIS_HOST', '172.17.0.1'),
  5. 'password' => env('REDIS_PASSWORD', null),//无密码要填null
  6. 'port' => env('REDIS_PORT', 6379),
  7. 'database' => 0,
  8. ],
  9. 'options' => [
  10. 'cluster' => 'redis',
  11. ],
  12. 'clusters' => [
  13. //集群1
  14. 'cluster1' => [
  15. [
  16. 'host' => '172.17.0.1',
  17. 'password' => null,//无密码要填null
  18. 'port' => 6379,
  19. 'database' => 0,
  20. ],
  21. ],
  22. //集群2
  23. 'cluster2' => [
  24. [
  25. 'host' => '192.168.31.244',
  26. 'password' => null,//无密码要填null
  27. 'port' => 6379,
  28. 'database' => 0,
  29. ],
  30. ],
  31. ],
  32. ],
正确的连接示例:
  1. $redis = Redis::connection('cluster1');
  2. $redis->set('username','wdh');
  3. echo $redis->get('username');

其他参考:

  1. 1.Laravel redis集群:https : // www . cnblogs . com /yinguohai/p/11329273.html

发表评论

表情:
评论列表 (有 0 条评论,124人围观)

还没有评论,来说两句吧...

相关阅读

    相关 laravel groupBy

    做个记录,在项目在本地正常,然后部署到服务器上就报错了,按网上说的改掉了mysql的配置后还是不行 最后改了一下laravel配置文件就好了,记录一下 `config/da