GithubHelp home page GithubHelp logo

xinson / redis-queue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from walkor/redis-queue

0.0 1.0 0.0 15 KB

Message queue system written in PHP based on workerman and backed by Redis.

PHP 100.00%

redis-queue's Introduction

redis-queue

Message queue system written in PHP based on workerman and backed by Redis.

Install

composer require workerman/redis-queue

Usage

test.php

<?php
require __DIR__ . '/vendor/autoload.php';

use Workerman\Worker;
use Workerman\Lib\Timer;
use Workerman\RedisQueue\Client;

$worker = new Worker();
$worker->onWorkerStart = function () {
    $client = new Client('redis://127.0.0.1:6379');
    $client->subscribe('user-1', function($data){
        echo "user-1\n";
        var_export($data);
    });
    $client->subscribe('user-2', function($data){
        echo "user-2\n";
        var_export($data);
    });
    Timer::add(1, function()use($client){
        $client->send('user-1', ['some', 'data']);
    });
};

Worker::runAll();

Run with command php test.php start or php test.php start -d.

API


__construct (string $address, [array $options])

Create an instance by $address and $options.

  • $address for example redis://ip:6379.

  • $options is the client connection options. Defaults:

    • auth: default ''
    • db: default 0
    • retry_seconds: Retry interval after consumption failure
    • max_attempts: Maximum number of retries after consumption failure

send(String $queue, Mixed $data, [int $dely=0])

Send a message to a queue

  • $queue is the queue to publish to, String
  • $data is the message to publish, Mixed
  • $dely is delay seconds for delayed consumption, Int

subscribe(mixed $queue, callable $callback)

Subscribe to a queue or queues

  • $queue is a String queue or an Array which has as keys the queue name to subscribe.
  • $callback - function (Mixed $data), $data is the data sent by send($queue, $data).

unsubscribe(mixed $queue)

Unsubscribe from a queue or queues

  • $queue is a String queue or an array of queue to unsubscribe from

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.