nasustop/hapi-mongo

1.0.0 2023-04-04 02:50 UTC

This package is auto-updated.

Last update: 2024-09-28 05:41:16 UTC


README

hyperf的mongo协程组件

目前,Swoole 无法 hook 所有阻塞函数,这意味着某些函数仍然会导致进程阻塞,从而影响协程的调度。由于 MongoDB 无法被 hook,因此当前项目会阻塞进程,请谨慎使用。参考文档:https://hyperf.wiki/3.0/#/zh-cn/task

在生产环境中使用mongo,请参考hapi-sidecar边车服务

安装

composer require nasustop/hapi-mongo

声明配置文件

php bin/hyperf.php vendor:publish nasustop/hapi-mongo

添加索引

mongo()->cmd([
    // 集合名
    'createIndexes' => 'api_log',
    'indexes' => [
        [
            // 索引名
            'name' => 'msg_code_index',
            // 索引字段数组[1升序,-1降序]
            'key' => ['msg_code' => 1],
        ],
    ],
]);