PHPackages                             mix/redis-subscriber - 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-subscriber

ActiveLibrary[Caching](/categories/caching)

mix/redis-subscriber
====================

Redis native protocol Subscriber based on Swoole coroutine

v3.0.6(2y ago)151.8M↓18.7%32Apache-2.0PHPPHP &gt;=7.0.0CI failing

Since Oct 25Pushed 1y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (1)Versions (18)Used By (2)

Mix Redis Subscriber
--------------------

[](#mix-redis-subscriber)

Redis native protocol Subscriber based on Swoole coroutine

基于 Swoole 协程的 Redis 原生协议订阅库

使用 Socket 直接连接 Redis 服务器，不依赖 phpredis 扩展，该订阅器有如下优点：

- 平滑修改：可随时增加、取消订阅通道，实现无缝切换通道的需求。
- 跨协程安全关闭：可在任意时刻关闭订阅。
- 通道获取消息：该库封装风格参考 golang 语言 [go-redis](https://github.com/go-redis/redis) 库封装，通过 channel 获取订阅的消息。

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

[](#installation)

- Swoole &gt;= 4.4

```
composer require mix/redis-subscriber

```

订阅频道
----

[](#订阅频道)

- 连接、订阅失败会抛出异常

```
$sub = new \Mix\Redis\Subscriber\Subscriber('127.0.0.1', 6379, '', 5); // 连接失败将抛出异常
$sub->subscribe('foo', 'bar'); // 订阅失败将抛出异常

$chan = $sub->channel();
while (true) {
    $data = $chan->pop();
    if (empty($data)) { // 手动close与redis异常断开都会导致返回false
        if (!$sub->closed) {
            // redis异常断开处理
            var_dump('Redis connection is disconnected abnormally');
        }
        break;
    }
    var_dump($data);
}
```

接收到订阅消息：

```
object(Mix\Redis\Subscriber\Message)#8 (2) {
  ["channel"]=>
  string(2) "foo"
  ["payload"]=>
  string(4) "test"
}

```

全部方法
----

[](#全部方法)

方法描述subscribe(string ...$channels) : void增加订阅unsubscribe(string ...$channels) : void取消订阅channel() : Swoole\\Coroutine\\Channel获取消息通道close() : void关闭订阅License
-------

[](#license)

Apache License Version 2.0,

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~101 days

Recently: every ~232 days

Total

17

Last Release

776d ago

Major Versions

v2.2.16 → v3.0.12021-08-09

### 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 (8 commits)")[![PandaLIU-1111](https://avatars.githubusercontent.com/u/26201936?v=4)](https://github.com/PandaLIU-1111 "PandaLIU-1111 (6 commits)")[![huangdijia](https://avatars.githubusercontent.com/u/8337659?v=4)](https://github.com/huangdijia "huangdijia (3 commits)")

---

Tags

coroutineredissubscribesubscriberswooleredisswoolesubscribesubscribermix

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[clue/redis-protocol

A streaming Redis protocol (RESP) parser and serializer written in pure PHP.

5311.0M13](/packages/clue-redis-protocol)[swoft/redis

swoft redis component

12168.4k16](/packages/swoft-redis)[rtcamp/nginx-helper

Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also provides cloudflare edge cache purging with Cache-Tags.

23817.0k1](/packages/rtcamp-nginx-helper)

PHPackages © 2026

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