Overview:
- Redis supports PUB/SUB
- It supports pattern matching. Clients may subscribe to glob-style patterns in order to receive all the messages sent to channel names matching a given pattern.
Assuming Fedora 23.
dnf install redis
systemctl start redis
systemctl enable redis
dnf install python
pip install redis
One terminal with:
./listener.py
Another with
redis-cli # opens a repl, all subsequent commands should show something in the first terminal
> publish hausmeister "new_user_created 123456" # I made up the convention of the message (action)
> publish worker.control "new_job 123456"
> publish worker.registration "done 123456" # yes we can use nested queues
> publish nirvana "nobody listens" # the listener is not subscribed, hence, we should not see anything
> publish worker.control KILL # terminate `listener.py`
When in Python3, it's better to add
decode_responses=True
when start redis.r = redis.Redis('127.0.0.1', decode_responses=True)