PHPackages                             marko/pubsub-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. [Framework](/categories/framework)
4. /
5. marko/pubsub-redis

ActiveMarko-module[Framework](/categories/framework)

marko/pubsub-redis
==================

Redis pub/sub driver for Marko Framework

0.7.0(3w ago)08MITPHPPHP ^8.5

Since Mar 25Pushed 3w agoCompare

[ Source](https://github.com/marko-php/marko-pubsub-redis)[ Packagist](https://packagist.org/packages/marko/pubsub-redis)[ RSS](/packages/marko-pubsub-redis/feed)WikiDiscussions develop Synced 3w ago

READMEChangelogDependencies (20)Versions (18)Used By (0)

marko/pubsub-redis
==================

[](#markopubsub-redis)

Non-blocking Redis pub/sub for Marko -- publish and subscribe over Redis with pattern support, powered by amphp for async I/O.

Overview
--------

[](#overview)

`marko/pubsub-redis` implements the `marko/pubsub` contracts using Redis PUB/SUB. `RedisPublisher` calls `PUBLISH` and `RedisSubscriber` supports both channel subscriptions (`SUBSCRIBE`) and pattern subscriptions (`PSUBSCRIBE`), making it the only built-in driver that supports `psubscribe()`. All I/O is non-blocking via `amphp/redis`.

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

[](#installation)

```
composer require marko/pubsub-redis
```

This automatically installs `marko/pubsub` and `marko/amphp`.

Usage
-----

[](#usage)

The module binding wires `PublisherInterface` → `RedisPublisher` and `SubscriberInterface` → `RedisSubscriber` automatically. Type-hint against the interfaces in your services.

```
use Marko\PubSub\Message;
use Marko\PubSub\PublisherInterface;
use Marko\PubSub\SubscriberInterface;

// Publishing
$publisher->publish(
    channel: 'user.42',
    message: new Message(
        channel: 'user.42',
        payload: json_encode(['text' => 'Hello!']),
    ),
);

// Channel subscription
$subscription = $subscriber->subscribe('user.42');

foreach ($subscription as $message) {
    $data = json_decode($message->payload, true);
}

$subscription->cancel();

// Pattern subscription (Redis-only feature)
$subscription = $subscriber->psubscribe('user.*');

foreach ($subscription as $message) {
    // $message->pattern contains the matched pattern
    $data = json_decode($message->payload, true);
}
```

Configure the Redis connection in `config/pubsub-redis.php`:

```
return [
    'host'     => '127.0.0.1',
    'port'     => 6379,
    'password' => null,
    'database' => 0,
];
```

API Reference
-------------

[](#api-reference)

### `RedisPublisher`

[](#redispublisher)

Implements `PublisherInterface`. Applies the configured channel prefix and calls Redis `PUBLISH`.

```
public function publish(string $channel, Message $message): void;
```

### `RedisSubscriber`

[](#redissubscriber)

Implements `SubscriberInterface`. Supports both exact channel and pattern subscriptions.

```
public function subscribe(string ...$channels): Subscription;   // Redis SUBSCRIBE
public function psubscribe(string ...$patterns): Subscription;  // Redis PSUBSCRIBE
```

### `RedisSubscription`

[](#redissubscription)

Iterates incoming Redis messages as `Message` instances. Implements `Subscription` (`IteratorAggregate`).

```
public function getIterator(): Generator; // yields Message
public function cancel(): void;
```

### `RedisPubSubConnection`

[](#redispubsubconnection)

Manages the `amphp/redis` client used by the publisher and the connector used by the subscriber.

### `AmphpRedisSubscriberInterface` / `DefaultAmphpRedisSubscriber`

[](#amphpredissubscriberinterface--defaultamphpredissubscriber)

Internal abstraction over the `amphp/redis` subscriber. `DefaultAmphpRedisSubscriber` is the production implementation; the interface exists to allow substitution in tests.

Documentation
-------------

[](#documentation)

Full usage, API reference, and examples: [marko/pubsub-redis](https://marko.build/docs/packages/pubsub-redis/)

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance94

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~4 days

Recently: every ~13 days

Total

16

Last Release

27d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/437029?v=4)[Mark Shust](/maintainers/markshust)[@markshust](https://github.com/markshust)

---

Top Contributors

[![markshust](https://avatars.githubusercontent.com/u/437029?v=4)](https://github.com/markshust "markshust (7 commits)")

###  Code Quality

TestsPest

### Embed Badge

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

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

PHPackages © 2026

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