PHPackages                             mix/redis - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. mix/redis

ActiveLibrary[Caching](/categories/caching)

mix/redis
=========

Coroutine redis library based on Swoole, built-in connection pool

v3.0.11(3y ago)510.1k↓66.7%413Apache-2.0PHPPHP &gt;=7.2.0CI failing

Since Dec 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mix-php/redis)[ Packagist](https://packagist.org/packages/mix/redis)[ Docs](https://openmix.org/mix-php)[ RSS](/packages/mix-redis/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (39)Used By (13)

> OpenMix 出品：[https://openmix.org](https://openmix.org/mix-php)

Mix Redis
=========

[](#mix-redis)

PHP Redis for use in multiple execution environments, with support for FPM, CLI, Swoole, WorkerMan, and optional connection pool (coroutine)

可在各种环境中使用的 PHP Redis，支持 FPM、CLI、Swoole、WorkerMan，可选的连接池 (协程)

技术交流
----

[](#技术交流)

知乎：
官方QQ群：[284806582](https://shang.qq.com/wpa/qunwpa?idkey=b3a8618d3977cda4fed2363a666b081a31d89e3d31ab164497f53b72cf49968a), [825122875](http://shang.qq.com/wpa/qunwpa?idkey=d2908b0c7095fc7ec63a2391fa4b39a8c5cb16952f6cfc3f2ce4c9726edeaf20)敲门暗号：redis

Installation
------------

[](#installation)

```
composer require mix/redis

```

Quick start
-----------

[](#quick-start)

注意：[协程环境中，不可在并发请求中使用单例](https://openmix.org/mix-php/docs/3.0/#/zh-cn/instructions?id=%e5%8d%8f%e7%a8%8b%e5%8d%95%e4%be%8b%e5%ae%9e%e4%be%8b%e5%8c%96)

```
$rds = new Mix\Redis\Redis('127.0.0.1', 6379, 'password', 0);

$rds->set('foo', 'bar');
$value = $rds->get('foo');
```

Start Pool
----------

[](#start-pool)

在 `Swoole` 协程环境中，启动连接池

```
$maxOpen = 50;        // 最大开启连接数
$maxIdle = 20;        // 最大闲置连接数
$maxLifetime = 3600;  // 连接的最长生命周期
$waitTimeout = 0.0;   // 从池获取连接等待的时间, 0为一直等待
$rds->startPool($maxOpen, $maxIdle, $maxLifetime, $waitTimeout);
Swoole\Runtime::enableCoroutine(); // 必须放到最后，防止触发协程调度导致异常
```

连接池统计

```
$rds->poolStats(); // array, fields: total, idle, active
```

Transaction Multi &amp; Pipeline
--------------------------------

[](#transaction-multi--pipeline)

Multi

事务块内的多条命令会按照先后顺序被放进一个队列当中，最后由exec命令原子性(atomic)地执行。

```
$tx = $rds->multi();
$tx->set('foo', 'bar');
$tx->set('foo1', 'bar1');
$ret = $tx->exec();
```

Pipeline

客户端将执行的命令写入到缓冲中，最后由exec命令一次性发送给redis执行返回。

```
$tx = $rds->pipeline();
$tx->set('foo', 'bar');
$tx->set('foo1', 'bar1');
$ret = $tx->exec();
```

Transaction Watch
-----------------

[](#transaction-watch)

监听值的变化，如果执行时有变化则事务失败，无变化则事务成功。

```
$tx = $rds->watch('foo');
$tx->incr('foo');
$ret = $tx->exec();
```

Logger
------

[](#logger)

日志记录器，配置后可打印全部SQL信息

```
$db->setLogger($logger);
```

`$logger` 需实现 `Mix\Redis\LoggerInterface`

```
interface LoggerInterface
{
    public function trace(float $time, string $cmd, array $args, ?\Throwable $exception): void;
}
```

License
-------

[](#license)

Apache License Version 2.0,

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 98.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~37 days

Recently: every ~101 days

Total

38

Last Release

1331d ago

Major Versions

v2.2.16 → v3.0.12021-07-08

PHP version history (2 changes)v2.0.1-Beta2PHP &gt;=7.0.0

v3.0.1PHP &gt;=7.2.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16074765?v=4)[LIU JIAN](/maintainers/onanying)[@onanying](https://github.com/onanying)

---

Top Contributors

[![onanying](https://avatars.githubusercontent.com/u/16074765?v=4)](https://github.com/onanying "onanying (59 commits)")[![bbuugg](https://avatars.githubusercontent.com/u/64066545?v=4)](https://github.com/bbuugg "bbuugg (1 commits)")

---

Tags

mixpoolredisswooleworkermanredisswoolecoroutinemixconnection-pool

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mix-redis/health.svg)

```
[![Health](https://phpackages.com/badges/mix-redis/health.svg)](https://phpackages.com/packages/mix-redis)
```

###  Alternatives

[mix/redis-subscriber

Redis native protocol Subscriber based on Swoole coroutine

151.8M2](/packages/mix-redis-subscriber)[mix/mix

PHP CLI mode development framework

1.9k1.2k](/packages/mix-mix)[swoft/redis

swoft redis component

12168.4k16](/packages/swoft-redis)[mix/grpc

PHP gRPC based on Swoole coroutine, including protoc code generator, server, and client

583.0k3](/packages/mix-grpc)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
