项目作者: limen

项目描述 :
Queue, Stack and Priority Queue built on Redis
高级语言: PHP
项目地址: git://github.com/limen/fastrq-php.git
创建时间: 2018-11-25T08:51:58Z
项目社区:https://github.com/limen/fastrq-php

开源协议:MIT License

下载


Fastrq - Queue, Stack and Priority Queue based on Redis

Build Status

Wiki

Fastrq for Python

Features

  • Abstract Queue, Deque, Capped Queue/Deque, and Overflow-able Capped Queue/Deque
  • Abstract Stack, Capped Stack
  • Abstract Priority Queue, Capped Priority Queue and Overflow-able Capped Priority Queue
  • Push and Pop support batch operation
  • Using Lua scripts to save RTT (Round Trip Time)

more in Wiki

install

Recommend to install via composer

  1. composer require limen/fastrq

Usage

  1. use Limen\Fastrq\Queue;
  2. use Limen\Fastrq\Deque;
  3. use Limen\Fastrq\Stack;
  4. use Limen\Fastrq\PriorityQueue;
  5. // queue
  6. $q = new Queue('fastrq-queue');
  7. $q->push(['hello', 'world']);
  8. $q->push('!!');
  9. $q->pop();
  10. $q->pop(2);
  11. $q->pushNI('hello');
  12. $q->pushAE('from');
  13. $q->pushNE(['from', 'fastrq']);
  14. // deque
  15. $dq = new Deque('fastrq-deque');
  16. $dq->pushFront(['hello', 'world']);
  17. $dq->pushBack('!!');
  18. $dq->popFront();
  19. $dq->popBack(2);
  20. $dq->pushFrontNI('hello');
  21. $dq->pushBackNI('hello');
  22. $dq->pushFrontNE('from');
  23. $dq->pushBackNE(['from', 'fastrq']);
  24. $dq->pushFrontAE('from');
  25. $dq->pushBackAE(['from', 'fastrq']);
  26. // stack
  27. $s = new Stack('fastrq-stack');
  28. $s->push(['hello', 'world']);
  29. $s->push('!!');
  30. $s->pop();
  31. $s->pop(2);
  32. $s->pushNI('hello');
  33. $s->pushAE('from');
  34. $s->pushNE(['from', 'fastrq']);
  35. // priority queue
  36. $pq = new PriorityQueue('fastrq-priority-queue');
  37. $pq->push(['hello' => 1]);
  38. $pq->push(['hello' => 1, 'world' => 2]);
  39. $pq->pushNI('fastrq', 2);
  40. $pq->pushAE(['hello' => 1, 'world' => 2]);
  41. $pq->pushNE(['hello' => 1, 'world' => 2]);

Data types

Queue

  • first in and first out
  • unlimited capacity
  • support batch push and batch pop

Deque

Derive from queue with more features

  • support push front and push back
  • support pop front and pop back

Capped Queue/Deque

Derive from queue/deque with more features

  • Have fixed capacity
  • Push to a full one would fail
  • Push to one whose positions are not enough would fail

Overflow-able Capped Queue/Deque

Derive from capped queue/deque with more features

  • The queue length would never exceed its capacity
  • Push to an end would push out from the other end if one is full

Stack

  • Last in and First out
  • Unlimited capacity
  • Support batch push and batch pop

Capped Stack

Derive from Stack with more features

  • Have fixed capacity
  • Push to a full capped stack would fail
  • Push to a capped stack whose positions are not enough would fail

Priority Queue

  • The lower the score, the higher the priority
  • Unlimited capacity
  • Support batch push and batch pop

Capped Priority Queue

Derive from Priority Queue with more features

  • Have fixed capacity
  • Push to a full one would fail
  • Push to a capped one whose positions are not enough would fail

Overflow-able Capped Priority Queue

Derive from Capped Priority Queue with more features

  • The queue length would never exceed its capacity
  • Push to an end would push out from the other end if queue is full