Skip to content

shixiongfei/redque

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redque

A distributed queue based on Redis

Installation

pip install redque

Example

import time
import random
import threading
import redis
import redque


def productor(redis_conn):
    other_queue = redque.Queue(redis_conn, "__test", "bp__test")

    for _ in range(100):
        other_queue.push("e_{0}".format(random.randint(1, 100)))
        time.sleep(0.1)


if __name__ == "__main__":
    pool = redis.ConnectionPool(
        host="127.0.0.1",
        port=6379,
        password="123456"
    )

    queue = redque.Queue(
        redis.Redis(connection_pool=pool),
        "__test",
        "bp__test"
    )
    queue.clear(True)

    # non-blocking
    for _ in range(100):
        queue.push(random.randint(1, 100))

    queue.process(lambda x: (print(x), True), False)

    # blocking
    t = threading.Thread(target=productor,
                        args=(redis.Redis(connection_pool=pool),))
    t.start()

    queue.process(lambda x: (print(x), True), timeout=3)

    t.join()

Releases

No releases published

Packages

No packages published

Languages