Skip to content

Commit

Permalink
init commit, no idea why this wasn't in git
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Feb 28, 2011
0 parents commit 267e644
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.DS_Store
*.swp
15 changes: 15 additions & 0 deletions pub.rb
@@ -0,0 +1,15 @@
# usage:
# ruby pub.rb channel username

require 'rubygems'
require 'redis'
require 'json'

$redis = Redis.new

data = {"user" => ARGV[1]}

loop do
msg = STDIN.gets
$redis.publish ARGV[0], data.merge('msg' => msg.strip).to_json
end
14 changes: 14 additions & 0 deletions sub.rb
@@ -0,0 +1,14 @@
require 'rubygems'
require 'redis'
require 'json'

$redis = Redis.new(:timeout => 0)

$redis.subscribe('rubyonrails', 'ruby-lang', 'rubymidwest') do |on|
on.message do |channel, msg|
data = JSON.parse(msg)
puts "##{channel} - [#{data['user']}]: #{data['msg']}"
end
end


0 comments on commit 267e644

Please sign in to comment.