mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-19 17:56:43 +00:00
Add volatile queue
This commit is contained in:
parent
d615ebdbd9
commit
c4fca1b754
14
hexlib/db.py
14
hexlib/db.py
@ -29,6 +29,20 @@ class VolatileState:
|
|||||||
return RedisTable(self, table)
|
return RedisTable(self, table)
|
||||||
|
|
||||||
|
|
||||||
|
class VolatileQueue:
|
||||||
|
"""Quick and dirty volatile queue-like redis wrapper"""
|
||||||
|
|
||||||
|
def __init__(self, key, **redis_args):
|
||||||
|
self.rdb = redis.Redis(**redis_args)
|
||||||
|
self.key = key
|
||||||
|
|
||||||
|
def put(self, item):
|
||||||
|
self.rdb.sadd(self.key, item)
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
return self.rdb.spop(self.key)
|
||||||
|
|
||||||
|
|
||||||
class VolatileBooleanState:
|
class VolatileBooleanState:
|
||||||
"""Quick and dirty volatile dict-like redis wrapper for boolean values"""
|
"""Quick and dirty volatile dict-like redis wrapper for boolean values"""
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.24",
|
version="1.25",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from hexlib.db import VolatileState, VolatileBooleanState
|
from hexlib.db import VolatileState, VolatileBooleanState, VolatileQueue
|
||||||
|
|
||||||
|
|
||||||
class TestVolatileState(TestCase):
|
class TestVolatileState(TestCase):
|
||||||
@ -68,3 +68,14 @@ class TestVolatileBoolState(TestCase):
|
|||||||
self.assertTrue(s["c"]["1"])
|
self.assertTrue(s["c"]["1"])
|
||||||
del s["c"]["1"]
|
del s["c"]["1"]
|
||||||
self.assertFalse(s["c"]["1"])
|
self.assertFalse(s["c"]["1"])
|
||||||
|
|
||||||
|
|
||||||
|
class TestVolatileQueue(TestCase):
|
||||||
|
|
||||||
|
def test_simple(self):
|
||||||
|
s = VolatileQueue(key="test5")
|
||||||
|
|
||||||
|
s.put("test")
|
||||||
|
item = s.get()
|
||||||
|
|
||||||
|
self.assertTrue(item == b"test")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user