基于redis的分布式消息队列
styx的Python项目详细描述
styx是一个简单的库,它将一堆独立的Redis服务器转变为一个强大的分布式队列。 redis服务器不需要任何特殊配置,甚至不需要以任何方式了解彼此。这些信息排列松散。 可以找到Java版本here。Java和Python版本是兼容的,即消息 一个客户端发布的内容可以被另一个客户端读取。
安装
pipinstallstyx
快速启动
#!/usr/bin/env python# encoding: utf-8importstyx# 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 automaticallyq=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 queueq.size()# returns 1# Delete this queueconnection.delete_queue(q)
单元测试
要运行单元测试,请确保有3个redis实例在本地主机上的6700、6701、6702端口上运行。
pip install nose nosetests
github上提供的源代码:http://github.com/abh1nav/styx-python/