PHPackages                             olegkravec/laravel-redis-router - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. olegkravec/laravel-redis-router

ActiveLibrary[HTTP &amp; Networking](/categories/http)

olegkravec/laravel-redis-router
===============================

Redis Pub/Sub router for Laravel

1.2.5(5y ago)22211PHPPHP \*

Since Nov 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Olegkravec/laravel-redis-router)[ Packagist](https://packagist.org/packages/olegkravec/laravel-redis-router)[ RSS](/packages/olegkravec-laravel-redis-router/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (3)Versions (20)Used By (0)

laravel-redis-router
====================

[](#laravel-redis-router)

Installing
----------

[](#installing)

`composer require olegkravec/laravel-redis-router`

General
-------

[](#general)

laravel-redis-router is implementation similar ro Laravel MVC scheme for handling and sending Redis Pub/Sub messages

How it is working?
------------------

[](#how-it-is-working)

For example you have 2 different services, called as Service A and Service B, both of services is REST(doesnt metter) API applications, but Service B must get data from Service A. There are different way how to receive data, for example HTTP API requests, but in highload projects http requests up to version 3 is too slow for transiving data between services, so we need something better.

Redis Pub/Sub mechanism allows subscribe to channel, and publish message to all subscribers, all subscribes will receive data in real time.

We will make example where Service A will subscribe to channel `users:*` and receive all requests and will send back to channel response. Service B will requests some specific data(User).

### Step 1 - registering Service A

[](#step-1---registering-service-a)

For lounching laravel-redis-router we should run: `php artisan listen:service users`

That's mean that Service A will subscribe for {users} channel.

### Step 2 - service controller for Service A

[](#step-2---service-controller-for-service-a)

`php artisan make:controller UserRedisController`

**Patter for creation:** {SERVICE\_NAME}RedisController For example: for notification service we must register ***NotificationRedisController***... eg...

### Step 3 - implementing first method for Service A

[](#step-3---implementing-first-method-for-service-a)

```
namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Support\Collection;
use OlegKravets\LaravelRedisService\Controllers\RedisCommandController;

class UserRedisController extends RedisCommandController
{
    protected static $bind_model = User::class;

    public static function test(string $data) : Collection {
        return new Collection(['ok!', "key" => $data . " World"]);
    }
}

```

First that you must to know: each controller can be bound to Model(Eloqument), thats allow request data from Service B directly from DB via present model

We implemented `test` method, that has argument `$data`, there is no limits with arguments, you can declare as much as you need, also it can be in any **basic** type.

\***Redis controller always must return Collection**

### Step 4 - requesting the data from Service B

[](#step-4---requesting-the-data-from-service-b)

#### Requesting controller's method

[](#requesting-controllers-method)

```
$out = new OutboundStream();
    $out->request("users:*", static function($response) {
        echo "Response is: $response";
    }, "test", "Hello");

```

In your console you will see: `Response is: {'0':"ok!", "key": "Hello World"}`

Response is `JSON` object with your data.

#### Requesting data directly from DB

[](#requesting-data-directly-from-db)

```
$out = new OutboundStream();
    $out->request("users:*", static function($response) {
        $user = json_decode($response);
        echo "Response is: " . $user->name;
    }, 'find', 1);

```

In your console you will see: `Response is: Oleg`

Response is `JSON` object with your data.

### How it looks in Redis Monitor

[](#how-it-looks-in-redis-monitor)

```
SERVICE A - "PSUBSCRIBE" "users:*"
SERVICE B - "PSUBSCRIBE" "users:322d3a41-c34c-46fe-aa7f-c3aff180a569"
SERVICE B - "PUBLISH" "users:6efc4e14-6679-49d9-be16-97246e02d32b" "request||where||[[\"id\",\"!=\",-65535]]"
SERVICE A - "PUBLISH" "users:6efc4e14-6679-49d9-be16-97246e02d32b" "response||[{\"id\":2,\"name\":\"Nayeli Kulas\",\"email\":\"dare.edgar@example.com\",\"email_verified_at\":\"2020-10-20T13:48:39.000000Z\",\"password\":\"\",\"created_at\":\"2020-10-20T13:48:39.000000Z\",\"updated_at\":\"2020-10-20T13:48:39.000000Z\"}]
SERVICE B - "PUNSUBSCRIBE" "users:6efc4e14-6679-49d9-be16-97246e02d32b"

```

1. Service A subscribes to all `users` channel with all package IDs.
2. Service B creates package `322d3a41-c34c-46fe-aa7f-c3aff180a569` and subscibes to it's channel
3. Service B sends to package's channel request `request||where||[[\"id\",\"!=\",-65535]]`
4. Service A, that parsed request calls method `where` firstly in Controller, in if not present in bound Model, generates Collection of response.
5. Generated response Service A sends to needed channel.
6. Service B unsubscribes package's channel.

Each package should have id, and as we cannot implement numerical inctementing id we just create UUID(for ex.: 322d3a41-c34c-46fe-aa7f-c3aff180a569)

### How is Protocol looks

[](#how-is-protocol-looks)

`request||where||[[\"id\",\"!=\",-65535]]`this string means that received redis Pub event is actually 'Request', and within it's Controller we should call 'where' method, with arguments '\[\["id","!=",-65535\]\]'

Argument can be not one, for example: `request||where||api_token||12345_token`

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

18

Last Release

1922d ago

Major Versions

0.1 → 1.1.12020-11-23

PHP version history (2 changes)0.1PHP &gt;=7.3.0

1.2PHP \*

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d64f8bb6a5ad1594fee0747529ba05227758254bce15bf70708c7422466cc25?d=identicon)[olegkravec](/maintainers/olegkravec)

---

Top Contributors

[![Olegkravec](https://avatars.githubusercontent.com/u/22846930?v=4)](https://github.com/Olegkravec "Olegkravec (19 commits)")

### Embed Badge

![Health badge](/badges/olegkravec-laravel-redis-router/health.svg)

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

###  Alternatives

[binaryk/laravel-restify

Laravel REST API helpers

651399.1k](/packages/binaryk-laravel-restify)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[lomkit/laravel-rest-api

A package to build quick and robust rest api for the Laravel framework.

59152.2k](/packages/lomkit-laravel-rest-api)[wirechat/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

5434.7k](/packages/wirechat-wirechat)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[georgeboot/laravel-echo-api-gateway

Use Laravel Echo with API Gateway Websockets

10435.5k](/packages/georgeboot-laravel-echo-api-gateway)

PHPackages © 2026

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