laravie/streaming 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laravie/streaming

最新稳定版本:v3.1.0

Composer 安装命令:

composer require laravie/streaming

包简介

Redis Async Streaming for PHP

README 文档

README

The project allows you as a developer to listen to Redis pubsub using async instead of blocking I/O using PHP. This is done by utilizing predis/predis-async under the hood.

tests Latest Stable Version Total Downloads Latest Unstable Version License Coverage Status

Installation

To install through composer, simply put the following in your composer.json file:

{
    "require": {
        "laravie/streaming": "^3.0"
    }
}

And then run composer install from the terminal.

Quick Installation

Above installation can also be simplify by using the following command:

composer require "laravie/streaming=^3.0"

Example

<?php

$eventLoop = React\EventLoop\Factory::create();

$chat = new class implements Laravie\Streaming\Listener {
    /**
     * @return array<int, string>
     */
    public function subscribedChannels(): array {
        return ['topic:*'];
    }
    
    /**
     * @param  \Predis\Async\Client  $redis  
     * @return void
     */
    public function onConnected($redis) {
        echo "Connected to redis!";
    }

    /**
     * @param  \Predis\Async\Client  $redis  
     * @return void
     */
    public function onSubscribed($redis) {
        echo "Subscribed to channel `topic:*`!";
    }
    
    /**
     * Trigger on emitted listener.
     *
     * @param  object  $event
     * @param  object  $pubsub
     *
     * @return void
     */
    public function onEmitted($event, $pubsub) {
        // PUBLISH topic:laravel "Hello world"
        
        # DESCRIBE $event
        #
        # {
        #   "kind": "pmessage",
        #   "pattern": "topic:*",
        #   "channel": "topic:laravel",
        #   "payload": "Hello world"
        # }
    }
}

$client = new Laravie\Streaming\Client(
    ['host' => '127.0.0.1', 'port' => 6379], $eventLoop
);

$client->connect($chat);

$eventLoop->run();

统计信息

  • 总下载量: 16.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 25
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-03