Skip to content

Instantly share code, notes, and snippets.

@alekpopovic
Forked from dkam/gist:9755012
Created August 10, 2022 09:14
Show Gist options
  • Save alekpopovic/e63e03055c2da9d18f5e685291e64112 to your computer and use it in GitHub Desktop.
Save alekpopovic/e63e03055c2da9d18f5e685291e64112 to your computer and use it in GitHub Desktop.
Postgresql pub/sub in Ruby
require 'sequel'
DB = Sequel.connect('postgres://user:pass@localhost/db')
DB.listen(:my_channel, loop: true) {|channel, pid, payload| puts "Got payload '#{payload}' on channel '#{channel}'" }
require 'sequel'
DB = Sequel.connect('postgres://user:pass@localhost/db')
DB.notify(:my_channel, payload: {a: 1, test: true} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment