webman Redis::get(): send of 28 bytes failed with errno=32 Broken pipe

mayibanjia

使用redis插件的时候 开发时 有时候刷新会出现这个

Redis::get(): send of 28 bytes failed with errno=32 Broken pipe
start.php 重启就好了 什么问题呢

2432 2 3
2个回答

walkor 打赏

哪个redis插件?

  • mayibanjia 2022-03-28

    webman的redis组件默认使用的是illuminate/redis,也就是laravel的redis库,用法与laravel相同。

  • mayibanjia 2022-03-28

    并没有找到可以断线重连设置的地方 我用的是阿里云的 redis数据库

  • walkor 2022-03-28

    阿里云好像会自动清理长时间不通讯的redis连接,导致下次使用的时候出现异常。稍等发你一段代码,加个定时器

  • mayibanjia 2022-03-28

    感恩

walkor 打赏

vendor/workerman/webman-framework/src/support/Redis.php 改成这样试下,
注意 instance()__callStatic方法有改动

class Redis
{

    /**
     * @var RedisManager
     */
    protected static $_instance = null;

    /**
     * @return RedisManager
     */
    public static function instance()
    {
        if (!static::$_instance) {
            $config = config('redis');
            static::$_instance = new RedisManager('', 'phpredis', $config);
        }
        return static::$_instance;
    }

    /**
     * @param string $name
     * @return \Illuminate\Redis\Connections\Connection
     */
    public static function connection($name = 'default')
    {
        static $timers = [];
        $connection = static::instance()->connection($name);
        if (!isset($timers[$name])) {
            $timers[$name] = Timer::add(55, function() use ($connection) {
                $connection->get('ping');
            });
        }
        return $connection;
    }

    /**
     * @param $name
     * @param $arguments
     * @return mixed
     */
    public static function __callStatic($name, $arguments)
    {
        return static::connection('default')->{$name}(... $arguments);
    }
}
  • mayibanjia 2022-03-28

    好的 谢谢大佬

  • mayibanjia 2022-03-28

    大佬,我src 下没有 support文件夹

  • mayibanjia 2022-03-28

    只有 一级目录 有这个 support/Redis.php

  • mayibanjia 2022-03-28

    class Redis
    {

    /**
     * @var RedisManager
     */
    protected static $_instance = null;
    
    /**
     * @return RedisManager
     */
    public static function instance()
    {
        if (!static::$_instance) {
            $config = config('redis');
            static::$_instance = new RedisManager('', 'phpredis', $config);
        }
        return static::$_instance;
    }
    
    /**
     * @param string $name
     * @return \Illuminate\Redis\Connections\Connection
     */
    public static function connection($name = 'default')
    {
        return static::instance()->connection($name);
    }
    
    /**
     * @param $name
     * @param $arguments
     * @return mixed
     */
    public static function __callStatic($name, $arguments)
    {
        return static::instance()->connection('default')->{$name}(... $arguments);
    }

    }

  • walkor 2022-03-28

    那就改 support/Redis.php

  • mayibanjia 2022-03-28

    已经改了 谢谢

年代过于久远,无法发表回答
×
🔝