Giter VIP home page Giter VIP logo

quedis's Introduction

quedis

Latest Version on Packagist Software License Build Status Coverage Status Quality Score

Install

  • PHP 5.6+
# via composer
$ composer require simplario/quedis

Testing

$ composer test

Start working

<?php

// Bootstrap
// =========================================

require_once(__DIR__ . '/vendor/autoload.php');

// Init
// =========================================

$redis = new \Predis\Client();
$quedis = new \Simplario\Quedis\Queue($redis, 'ExampleNameSpace');


// Put message to Quedis
// =========================================


// add new messages
$message11 = $quedis->put('transaction-queue', 'transaction-11');
$message12 = $quedis->put('transaction-queue', new \Simplario\Quedis\Message('transaction-12'));


// with delay
$message22 = $quedis->put('transaction-queue', 'transaction-21', 60 * 5);
$message22 = $quedis->put('transaction-queue', 'transaction-22', (new \DateTime())->modify('+1 day'));


// with priority
$message32 = $quedis->put('transaction-queue', 'transaction-31', 0, 'high');
$message32 = $quedis->put('transaction-queue', 'transaction-32', 0, 'low');


// Get Quedis statistic
// =========================================


// for concrete queue
$queueStat = $quedis->stats('transaction-queue');


// for all queues
$statsAll = $quedis->stats();


// Stop/start queue
// =========================================


// stop queue
$quedis->stop('transaction-queue');


// for all queues
$quedis->start('transaction-queue');


// check
$isStop = $quedis->isStop('transaction-queue');
print_r($isStop);


/**
 *
 * Take message from Quedis
 *
 *   Message flows (like in the Beanstalk: http://beanstalkc.readthedocs.io/en/latest/tutorial.html )
 *   ------------------------------------------------------------------------------------------------
 *
 *   1)   put            pop
 *       -----> [READY] --------> *poof*
 *
 *
 *   2)   put            reserve               delete
 *       -----> [READY] ---------> [RESERVED] --------> *poof*
 *
 *
 *   3)   put with delay               release with delay
 *       ----------------> [DELAYED] <------------.
 *                             |                   |
 *                             | (time passes)     |
 *                             |                   |
 *        put                  v     reserve       |       delete
 *       -----------------> [READY] ---------> [RESERVED] --------> *poof*
 *                            ^  ^                |  |
 *                            |   \  release      |  |
 *                            |    ``-------------'   |
 *                            |                      |
 *                            | kick                 |
 *                            |                      |
 *                            |       bury           |
 *                         [BURIED] <---------------'
 *                            |
 *                            |  delete
 *                             ``--------> *poof*
 *
 */


// just pop single message
$message = $quedis->pop('transaction-queue');
print_r($message);


// just pop single message with timeout (redis blpop timeout)
$message = $quedis->pop('transaction-queue', 10);
print_r($message);


// reserve flow
$message = $quedis->reserve('transaction-queue', 10);
$quedis->delete($message);


// reserve > bury > kick > reserve > delete
$message = $quedis->reserve('transaction-queue', 10);
// something goes wrong ...
$quedis->bury($message);
// ok lets retry one more time ...
$quedis->kick($message);
$messageSame = $quedis->reserve($message);
// all is ok!
$quedis->delete($messageSame);


// Iterator usage
// =========================================


// iterate reserve all messages
$iterator = $quedis->iterator('transaction-queue', 'reserve', 10);
foreach($iterator as $index => $message){
    print_r($message);

    $quedis->delete($message);
}


// or like standalone with pop logic
$queue = new \Simplario\Quedis\Queue(new \Predis\Client(), 'super-puper-quedis');
$iterator = new \Simplario\Quedis\Iterator($queue, 'transaction-queue', 'pop', 10);
foreach($iterator as $index => $message){
    print_r($message);
}

License

The MIT License (MIT). Please see License File for more information.

quedis's People

Contributors

vlad-groznov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

quedis's Issues

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.