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 already inside the queue
  • Support pushing only if the queue already exists/not already exist
  • All operations are atomic

Requirements

  • Redis >=3.0.2
  • Python 2.7 or >=3.4

Installation

via pip

pip install fastrq

or from source

python setup.py install

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]. `ni` stands `not inside`
q.push_ae(1) # got 4. `ae` stands `already exists`
q.push_ne(1) # got False. `ne` stands `not already exist`
q.ttl(10)   # set the lifetime in seconds
q.range(0, -1)  # got ['1', '2', '3']
q.range(0, 1)  # got ['1', '2']
q.indexof_one(1); # got 0
q.indexof_one(2); # got 1
q.indexof_one(4); # got None
q.indexof_many([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 forced 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.indexof_one('google'); # got 0
pq.indexof_one('alibaba'); # got 1
pq.indexof_one('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.indexof_one(1); # got 2
s.indexof_one(2); # got 1
s.indexof_one(3); # got 0
s.pop()
s.push_ni(4)

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

Metadata

Release files for fastrq 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastrq 0.2.0
File Size Uploaded
fastrq-0.2.0.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastrq 0.2.0
File Interpreter ABI Platform
fastrq-0.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 23.0 kB

Release files / fastrq-0.2.0.tar.gz

Download URL fastrq-0.2.0.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
007ea721b0c189a66942a506c9c05666d0bdf4e7452123cc404149e99981b5a2
BLAKE2b-256 checksum
How to use checksums
5a01c791bd98f03f7d5dff086bc6f397e619afde2cc979aaf7f7f1d2ebe12abb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.4.3

Release files / fastrq-0.2.0-py2.py3-none-any.whl

Download URL fastrq-0.2.0-py2.py3-none-any.whl
Size 12.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
909ba63b3630057e8319ed9818c935cf47ad44973cf9186c4cdc09c22152746b
BLAKE2b-256 checksum
How to use checksums
45c66249ca26565817b66874b645dec8af80185d6c0f1d59d662b23adf9b97c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.4.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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