PHP Classes

PHP Queue System: Manage circular job queues stored in Redis

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 61 All time: 10,477 This week: 73Up
Version License PHP version Categories
circular-queue 1.0MIT/X Consortium ...7Databases, Tools, Data types, PHP 7
Description 

Author

This package can manage circular job queues stored in Redis.

It can create queue of job data storing the details of the data properties in a Redis key-value pair database.

The package can also perform other types of operations like pushing jobs to the queue, pull the next job in the queue, getting, delaying a job that was in the queue for a given period of time, resume a delayed job, get the count of jobs in the queue, etc..

Picture of Insolita
  Performance   Level  
Name: Insolita <contact>
Classes: 25 packages by
Country: Russian Federation Russian Federation
Age: 38
All time rank: 330590 in Russian Federation Russian Federation
Week rank: 50 Up6 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 18x

Documentation

Circular Queue

Circular Queue with redis implementation for distribution of shared data Useful for resource balancing, parsing

Build StatusScrutinizer Code QualitySensioLabsInsight

Install

composer require insolita/circular-queue

Usage

SimpleCircularQueue

  $q = new SimpleCircularQueue(
       'queueName',
        new AsIsConverter(),              // insolita\cqueue\Contracts\PayloadConverterInterface
        new OnEmptyQueueException(),      // insolita\cqueue\Contracts\EmptyQueueBehaviorInterface
        new PredisStorage(new Client())   // insolita\cqueue\Contracts\StorageInterface
  );

  $q->fill(['alpha', 'beta', 'gamma', 'delta']);
  $q->next(); //alpha
  $q->next(); //beta
  $q->next(); //gamma
  $q->next(); //delta
  $q->next(); //alpha
  $q->next(); //beta
  $q->next(); //gamma
  $q->countQueued();//4
  $q->purgeQueued();//clear queue
  ...

CircularQueue

  $q = new CircularQueue(
       'queueName',
        new AsIsConverter(),              // insolita\cqueue\Contracts\PayloadConverterInterface
        new OnEmptyQueueException(),      // insolita\cqueue\Contracts\EmptyQueueBehaviorInterface
        new PredisStorage(new Client())   // insolita\cqueue\Contracts\StorageInterface
  );
    $q->fill(['alpha', 'beta', 'gamma', 'delta']);
    $item = $q->pull(); //alpha - extract item from queue
    $q->resume($item); // resume item in queue

    $item1 = $q->pull(60); //Item will be resumed in queue after 60 seconds
    $item2 = $q->pull();
    $q->resume($item2, 120); //Item will be resumed in queue after 120 seconds
    $item3 = $q->pull();
    $q->resumeAt($item3, time()+100500); //Item will be resumed  after concrete timestamp
    $q->countTotal()   //4
    $q->countQueued()  //1
    $q->countDelayed() //3
    $q->listDelayed()  // ['beta', 'gamma', 'delta']
    $q->resumeAllDelayed(); //Force resume all delayed in queue
    $q->purgeDelayed(); //Remove all delayed

Manager

   $q1 = new CircularQueue(
                                 'firstQueue',
                                  new SerializableConverter(),
                                  new OnEmptyQueueException(),
                                  new PhpRedisStorage(new \Redis())
                            );
   $manager = new Manager([$q1]);
   $manager->add(new CircularQueue(
                           'secondQueue',
                            new SerializableConverter(),
                            new OnEmptyQueueException(),
                            new PhpRedisStorage(new \Redis())
                      ));

   $manager->queue('firstQueue')->fill([...]);
   $manager->queue('secondQueue')->fill([...]);
   ...
   $manager->remove('firstQueue');


  Files folder image Files (27)  
File Role Description
Files folder imagesrc (3 files, 5 directories)
Files folder imagetests (2 directories)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (27)  /  src  
File Role Description
Files folder imageBehaviors (2 files)
Files folder imageContracts (5 files)
Files folder imageConverters (2 files)
Files folder imageMixins (1 file)
Files folder imageStorage (2 files)
  Plain text file CircularQueue.php Class Class source
  Plain text file Manager.php Class Class source
  Plain text file SimpleCircularQueue.php Class Class source

  Files folder image Files (27)  /  src  /  Behaviors  
File Role Description
  Plain text file OnEmptyQueueException.php Class Class source
  Plain text file OnEmptyQueueResumeException.php Class Class source

  Files folder image Files (27)  /  src  /  Contracts  
File Role Description
  Plain text file DelayingInterface.php Class Class source
  Plain text file EmptyQueueBehaviorInterface.php Class Class source
  Plain text file PayloadConverterInterface.php Class Class source
  Plain text file QueueInterface.php Class Class source
  Plain text file StorageInterface.php Class Class source

  Files folder image Files (27)  /  src  /  Converters  
File Role Description
  Plain text file AsIsConverter.php Class Class source
  Plain text file SerializableConverter.php Class Class source

  Files folder image Files (27)  /  src  /  Mixins  
File Role Description
  Plain text file DelayingTrait.php Class Class source

  Files folder image Files (27)  /  src  /  Storage  
File Role Description
  Plain text file PhpRedisStorage.php Class Class source
  Plain text file PredisStorage.php Class Class source

  Files folder image Files (27)  /  tests  
File Role Description
Files folder imageFunctional (3 files)
Files folder imageUnit (5 files)

  Files folder image Files (27)  /  tests  /  Functional  
File Role Description
  Plain text file FunctionalPredisTest.php Class Class source
  Plain text file FunctionalRedisTest.php Class Class source
  Plain text file StorageSameTest.php Class Class source

  Files folder image Files (27)  /  tests  /  Unit  
File Role Description
  Plain text file CircularQueueTest.php Class Class source
  Plain text file ManagerTest.php Class Class source
  Plain text file SerializableConverterTest.php Class Class source
  Plain text file SimpleCircularQueueTest.php Class Class source
  Plain text file StorageTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:61
This week:0
All time:10,477
This week:73Up