Skip to content

Commit

Permalink
documentation; more clear parameters types; more clear returned types…
Browse files Browse the repository at this point in the history
…; rename same methods;
  • Loading branch information
limen committed Jan 2, 2019
1 parent feebfcc commit a7f2973
Show file tree
Hide file tree
Showing 12 changed files with 1,158 additions and 329 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
+ 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
+ Support pushing only if a member not inside the queue
+ All commands are `atomic`

## Data types

Expand Down Expand Up @@ -110,9 +111,9 @@ 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.indexof_one(1); # got 0
q.indexof_one(2); # got 1
q.indexof_one(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]
Expand Down Expand Up @@ -143,9 +144,9 @@ dq.push_back_ni(5)
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.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)
Expand All @@ -154,9 +155,9 @@ 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.indexof_one(1); # got 2
s.indexof_one(2); # got 1
s.indexof_one(3); # got 0
s.pop()
s.push_ni(4)

Expand Down
26 changes: 26 additions & 0 deletions fastrq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
""" Fastrq: Queue, Stack and Priority Queue built on Redis.
Data types:
- Queue: nothing more to say
- Capped Queue: Queue with fixed capacity.
- Overflow-able Capped Queue: Queue with fixed capacity, and is overflow-able.
- Stack: nothing more to say
- Capped Stack: Stack with fixed capacity
- Deque: nothing more to say
- Capped Deque: Deque with fixed capacity
- Overflow-able Capped Deque: Deque with fixed capacity, and is overflow-able.
- Priority Queue: nothing more to say
- Capped Priority Queue: Priority Queue with fixed capacity
- Overflow-able Priority Queue: Priority Queue with fixed capacity, and is overflow-able.
more detail, see https://github.com/limen/fastrq
"""


from __future__ import absolute_import

from . import queue, deque, stack, priorityqueue
Expand All @@ -6,9 +30,11 @@
name = 'fastrq'
__version__ = '0.1.3'


def version():
return __version__


__all__ = [
queue,
deque,
Expand Down
13 changes: 9 additions & 4 deletions fastrq/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from __future__ import absolute_import

from redis import StrictRedis

from . import loader


class Base(object):
def __init__(self, key):
Expand All @@ -8,6 +12,9 @@ def __init__(self, key):

def __len__(self):
return None

def load_script(self, command):
return loader.load(command)

def connect(self):
if self._redis is None:
Expand Down Expand Up @@ -44,10 +51,8 @@ def length(self):
def destruct(self):
return self.connect().delete(self._key)

def _makevalues(self, values):
if isinstance(values, tuple) or isinstance(values, list):
return tuple(values)
return values,
def _make_members(self, members):
return members if isinstance(members, list) else [members]

def _run_lua_script(self, script, keys=(), args=()):
func = self.connect().register_script(script)
Expand Down
Loading

0 comments on commit a7f2973

Please sign in to comment.