Permalink
Browse files

Prepare the redis connection for redis to go on Heroku

  • Loading branch information...
1 parent 75c2899 commit 3a935ef984fb1b3f650fb919a7ae67755b90bed5 @cc committed Mar 10, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 pastr_app.rb
View
8 pastr_app.rb
@@ -7,7 +7,9 @@
class PastrApp < Sinatra::Base
register Mustache::Sinatra
- @@redis = Redis.new(:host => 'localhost', :port => 6379)
+ ENV["REDISTOGO_URL"] = 'redis://localhost:6379' if ENV["RACK_ENV"] != 'production'
+ uri = URI.parse(ENV["REDISTOGO_URL"])
+ REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
require 'views/layout'
@@ -22,12 +24,12 @@ class PastrApp < Sinatra::Base
post '/' do
id = Digest::MD5.hexdigest(params[:code])
- @@redis.set "pastr:#{id}", params[:code]
+ REDIS.set "pastr:#{id}", params[:code]
redirect "/#{id}"
end
get '/:id' do |id|
- @code = @@redis.get "pastr:#{id}"
+ @code = REDIS.get "pastr:#{id}"
mustache :show
end
end

0 comments on commit 3a935ef

Please sign in to comment.