Skip to content

@pirj /Gemfile
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Sinatra streaming + Redis PubSub
require 'bundler'
Bundler.require
class App < Sinatra::Base
helpers Sinatra::Streaming
get '/' do
subscriber = EM::Hiredis.connect
subscriber.psubscribe '*'
stream :keep_open do |out|
subscriber.on(:pmessage) do |key, channel, message|
subscriber.punsubscribe '*' if out.closed?
out << "#{key}, #{channel}, #{message}" unless out.closed?
end
end
end
end
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib', require: 'sinatra/streaming'
group :development do
gem 'thin'
gem 'pry-rails'
end
gem 'eventmachine', "= 1.0.0.rc.4"
gem "redis", "~> 3.0"
gem "hiredis", "~> 0.4.5"
gem 'em-hiredis'
@pirj
Owner

Example client code (JS)

var xhr = new XMLHttpRequest()
xhr.open("GET", "/", true)
xhr.onprogress = function () {
  alert(xhr.responseText)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.