Skip to main content

Fastrq - Queue, Stack and Priority Queue built on Redis

Build Status

Fastrq for PHP

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)
  • Support getting indexes of members
  • Support pushing only if a member not inside the queue

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 would push out the lowest priority if queue is full

install

from source

python setup.py install

use pip

pip install fastrq

Usage

from fastrq.queue import Queue, CappedQueue
from fastrq.deque import Deque
from fastrq.stack import Stack
from fastrq.priorityqueue import PriorityQueue

# queue
q = Queue("fastrq_queue")
q.push(1)
q.push([2, 3])
q.push_ni(1) # got [3, False]
q.ttl(10)   # set the lifetime in seconds
q.range(0, -1)  # got ['1', '2', '3']
q.range(0, 1)  # got ['1', '2']
q.indexofone(1); # got 0
q.indexofone(2); # got 1 
q.indexofone(4); # got None
q.indexofmany([1, 2, 4]); # got {1: 0, 2: 1, 4: None}
# push only if the member not inside the queue
q.push_ni(4) # got [4, True]
q.pop()
q.pop(2)
q.destruct() # destruct the queue
cq = CappedQueue("fastrq_capped_queue", 3)
cq.push(1)
cq.push(2)
cq.push([3, 4]) # got "err_qof"
cq.push(3)
cq.push(4) # got "err_qf"
of_cq = OfCappedQueue("fastrq_of_capped_queue", 3)
of_cq.push(1)
of_cq.push([2, 3, 4])  # "1" would be pushed out


# deque
dq = Deque("fastrq_deque")
dq.push_front([1, 2])
dq.push_back([3, 4])
dq.pop_front()
dq.pop_back()
dq.push_front_ni(3)
dq.push_back_ni(5)

# priority queue
pq = PriorityQueue("fastrq_priority_queue")
pq.push({'alibaba': 1})
pq.push({'google': 0, 'microsoft': 2})
pq.indexofone('google'); # got 0
pq.indexofone('alibaba'); # got 1
pq.indexofone('baidu'); # got None
pq.pop()
pq.pop(2)
pq.push_ni('ibm', 4)
pq.push_ni('amazon', 5)

# stack
s = Stack("fastrq_stack")
s.push([1,2,3])
s.indexofone(1); # got 2
s.indexofone(2); # got 1
s.indexofone(3); # got 0
s.pop()
s.push_ni(4)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastrq-0.1.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastrq-0.1.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file fastrq-0.1.2.tar.gz.

File metadata

  • Download URL: fastrq-0.1.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for fastrq-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e6a6528d1b2efc92ed0a38e20104ea06b5b59f1f214539f66a66b4885b8cf711
MD5 311c09f755a2803dba37e8b27a96de97
BLAKE2b-256 09ad0e0a827537f086eb166e310c32b397c084c3192570afe16f0eea1178a17b

See more details on using hashes here.

File details

Details for the file fastrq-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fastrq-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for fastrq-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b2899f079f6160f35bbed8ba9c896888bdd8a96489396cfc7cd8d583f946fd88
MD5 237d6395f39a0f4f4b532a4952526f01
BLAKE2b-256 977bee606ce6b6209d4ae0de0e4d03270f1c1480830d82e03cc46e639537345b

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.0

2 files

0.1.3

2 files

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page