基于Redis的分布式消息队列
项目描述
Styx是一个简单的库,可以将多个独立的Redis服务器转换为一个强大的分布式队列。Redis服务器无需任何特殊配置,也不需要以任何方式相互了解。消息是松散排序的。可以在这里找到Java版本。Java和Python版本是兼容的 - 即一个客户端发布的消息可以被另一个客户端读取。
安装
pip install styx
快速入门
#!/usr/bin/env python
# encoding: utf-8
import styx
# Define the Redis host locations (the default port is 6379)
hosts = [ "redis1.example.com", "redis2.example.com:8080", "redis3.example.com" ]
connection = styx.Styx(hosts, db=3) # default db is 0
# If a queue doesn't exist, it will be created automatically
q = connection.get_queue("myTestQueue")
q.put("Hello")
q.put("World")
q.put("Message1234")
q.get() # returns "Hello"
q.get() # returns "World"
# Check how many messages are left in the queue
q.size() # returns 1
# Delete this queue
connection.delete_queue(q)
单元测试
要运行单元测试,请确保您在本地主机上以6700、6701、6702端口运行3个Redis实例。
pip install nose
nosetests
源代码在GitHub上可用: http://github.com/abh1nav/styx-python/
项目详情
关闭
styx-0.1.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | de57e2c622165cee10e32131a16a0e36be04974e07bcf146384972d8f0181aea |
|
MD5 | 63cf52666db656dcd9c2040bc6e59941 |
|
BLAKE2b-256 | a4767e983f644acd9e8f3a99202dbe152357bd09e511ad6c6b47d7dd0b955725 |