ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## Mix\Redis\Pool\ConnectionPool::class 通常频繁调用的数据库都会以连接池的方式获取连接,mix 的数据库连接池是基于一个独立的连接池库 [mix/pool](https://github.com/mix-php/pool) 开发的,其大概流程为: - 通过依赖注入获取连接池实例(单例) - 通过连接池获取连接 - 池内无可用连接时调用连接池的拨号器 dialer 创建新连接 ## 组件 使用 [composer]([https://www.phpcomposer.com/](https://www.phpcomposer.com/)) 安装: ~~~ composer require mix/redis ~~~ ## 依赖注入配置 - [beans/redis.php](https://github.com/mix-php/mix-skeleton/tree/v2.1/manifest/beans/redis.php) ## 通过池获取连接 通过连接池获取连接: ``` /** @var \Mix\Redis\Pool\ConnectionPool $redisPool */ $redisPool = context()->get('redisPool'); $redis = $redisPool->getConnection(); // ... $redis->release(); // 不手动释放的连接不会归还连接池,会在析构时丢弃 ```