【已解决】webman,redis协程,报错

tanhongbin
ArgumentCountError: key() expects exactly 1 argument, 2 given in E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\redis\src\Client.php:421
Stack trace:
#0 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\redis\src\Client.php(421): key(false, Object(Workerman\Redis\Client))
#1 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Connection\TcpConnection.php(711): Workerman\Redis\Client->Workerman\Redis\{closure}(Object(Workerman\Connection\AsyncTcpConnection), Array)
#2 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Events\Revolt.php(146): Workerman\Connection\TcpConnection->baseRead(Resource id #248)
#3 E:\phpstudy_pro\WWW\activity\mst\vendor\revolt\event-loop\src\EventLoop\Internal\AbstractDriver.php(571): Workerman\Events\Revolt->Workerman\Events\{closure}('g', Resource id #248)
#4 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#5 E:\phpstudy_pro\WWW\activity\mst\vendor\revolt\event-loop\src\EventLoop\Internal\AbstractDriver.php(478): Fiber->resume()
#6 E:\phpstudy_pro\WWW\activity\mst\vendor\revolt\event-loop\src\EventLoop\Internal\AbstractDriver.php(533): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
#7 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#8 E:\phpstudy_pro\WWW\activity\mst\vendor\revolt\event-loop\src\EventLoop\Internal\AbstractDriver.php(105): Fiber->start()
#9 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Events\Revolt.php(88): Revolt\EventLoop\Internal\AbstractDriver->run()
#10 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Worker.php(1444): Workerman\Events\Revolt->run()
#11 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Worker.php(1365): Workerman\Worker::forkWorkersForWindows()
#12 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Worker.php(572): Workerman\Worker::forkWorkers()
#13 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\webman-framework\src\support\App.php(131): Workerman\Worker::runAll()
#14 E:\phpstudy_pro\WWW\activity\mst\start.php(4): support\App::run()
#15 {main}

发下能重现问题的代码

926 1 0
1个回答

walkor

发下能重现问题的代码

  • tanhongbin 2023-06-08

    <?php

    namespace app\home\controller;

    use support\exception\BusinessException;
    use support\Request;
    use lib\ExcelRead;
    use support\Redis;
    use support\Container;
    use lib\RateLimiting;
    use support\Db;
    use Workerman\Redis\Client;

    class IndexController extends Base
    {
    private $redis;
    function __construct(){
    $this->redis = new Client('redis://' . envs('REDIS_HOST') . ':' . envs('REDIS_PORT'));
    $this->redis->auth(envs('REDIS_PASSWORD'));
    $this->redis->select(envs('REDIS_DATABASE'));
    }

    public function view(Request $request)
    {
        $r = $this->redis->get('key');
        return $this->json(0,'success',['data' => $r]);

    // $data = RateLimiting::getDbByLock('101_log','fuck',60,function(){
    // return (array)Db::table('tp_101_log')->where('id',138)->first();
    // });
    // return $this->json(0,'success',$data);
    }

    }

    请求 view方法 就后台报错了

    ArgumentCountError: key() expects exactly 1 argument, 2 given in E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\redis\src\Client.php:421
    Stack trace:

    0 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\redis\src\Client.php(421): key(false, Object(Workerman\Redis\Client))

    1 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Connection\TcpConnection.php(711): Workerman\Redis\Client->Workerman\Redis{closure}(Object(Workerman\Connection\AsyncTcpConnection), Array)

    2 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Events\Revolt.php(146): Workerman\Connection\TcpConnection->baseRead(Resource id #247)

    3 E:\phpstudy_pro\WWW\activity\mst\vendor\revolt\event-loop\src\EventLoop\Internal\AbstractDriver.php(571): Workerman\Events\Revolt->Workerman\Events{closure}('g', Resource id #247)

    4 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal{closure}()

    5 E:\phpstudy_pro\WWW\activity\mst\vendor\revolt\event-loop\src\EventLoop\Internal\AbstractDriver.php(478): Fiber->resume()

    6 E:\phpstudy_pro\WWW\activity\mst\vendor\revolt\event-loop\src\EventLoop\Internal\AbstractDriver.php(533): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()

    7 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal{closure}()

    8 E:\phpstudy_pro\WWW\activity\mst\vendor\revolt\event-loop\src\EventLoop\Internal\AbstractDriver.php(105): Fiber->start()

    9 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Events\Revolt.php(88): Revolt\EventLoop\Internal\AbstractDriver->run()

    10 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Worker.php(1444): Workerman\Events\Revolt->run()

    11 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Worker.php(1365): Workerman\Worker::forkWorkersForWindows()

    12 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\workerman\src\Worker.php(572): Workerman\Worker::forkWorkers()

    13 E:\phpstudy_pro\WWW\activity\mst\vendor\workerman\webman-framework\src\support\App.php(131): Workerman\Worker::runAll()

    14 E:\phpstudy_pro\WWW\activity\mst\start.php(4): support\App::run()

  • walkor 2023-06-08

    升级下 composer require workerman/redis ^2.0.2

  • tanhongbin 2023-06-08

    感谢老大,协程可以使用了,升级以后问题已经修复了

  • xiaopi 2023-07-25

    老哥我有个疑问啊,workerman-redis处理常规redis get、set稳定么?可以用于生产环境吗?根据手册上写的,除非要使用异步订阅功能,否则最好使用phpredis扩展,以获得更好的性能。

  • walkor 2023-07-25

    workerman/redis 没有看到说不稳定的反馈。
    不过get set建议用redis扩展,性能和workerman/redis区别不大,用法大家都熟悉。
    workerman/redis官方开发出来主要是用来处理非阻塞订阅的。

  • xiaopi 2023-07-25

    明白了,感谢

🔝