Skip to content

twiden/redis-pubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redis-pubsub

Python Redis pub-sub library

import redis
import random
import time
from twiden.pubsub import Publisher, Subscriber

HOST = '127.0.0.1'

def send():
	r = redis.Redis(host=HOST)
	p = Publisher(r, 'my publisher')
	for _ in range(1, 100):
		p.publish({'sleep': random.random()}, 'my topic', '1.0')

def receive():
	r = redis.Redis(host=HOST)
	filters = {
		'topic': lambda topic: topic == 'my topic',
		'version': lambda version: version >= '1.0',
	}
	Subscriber(r, 'my consumer').subscribe(handler, filters)

def handler(m):
	zzz = m['sleep']
	print 'Sleeping', zzz
	time.sleep(zzz)

About

Python Redis pub-sub library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages