Created
March 5, 2015 13:16
-
-
Save quommit/5b7b469648c795534018 to your computer and use it in GitHub Desktop.
Simple PostgreSQL plpython function for message publication through Redis pub/sub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION redis_pubsub.notify(channel text, message text, host text, port integer) | |
RETURNS void AS | |
$BODY$ | |
#Safeguard against null or empty values | |
if (channel is None) or (message is None): | |
return | |
if (host is None) or (host.strip() == ""): | |
redishost = "127.0.0.1" | |
else: | |
redishost = host | |
if (port is None) or (port <= 0): | |
redisport = 6379 | |
else: | |
redisport = port | |
import redis | |
#Get Redis connection | |
r = redis.StrictRedis(host=redishost, port=redisport, db=0) | |
#Publish message | |
r.publish(channel, message) | |
$BODY$ | |
LANGUAGE plpython3u VOLATILE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment