This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.
publish message to foo
channel from user nickname
.
$ python pub.py foo nickname
PUBLISH to channel #foo
test message
what's up?
<Ctrl-D>
$
publish message to bar
channel from user mike
.
$ python pub.py bar mike
PUBLISH to channel #bar
pub/sub rules!
<Ctrl-D>
$
subscribe to foo
or bar
channel.
$ python sub.py foo bar
SUBSCRIBE TO channel #foo
SUBSCRIBE TO channel #bar
#foo - [nickname]:test message
#foo - [nickname]:what's up?
#bar - [mike]:pub/sub rules!
<Ctrl-C>
UNSUBSCRIBE FROM channel #foo
UNSUBSCRIBE FROM channel #bar
$
Keep in mind that PostgreSQL's LISTEN/NOTIFY wont send/receive until the current transaction is committed with success. So, for example, if you have some long transaction and several NOTIFYs within it in different life time, you won't get them instantly one after another, you'll get them at once as soon as the transaction is committed successfully. So, yeah, PostgreSQL can't REALLY Pub/Sub like Redis, sadly.