Created
January 23, 2013 23:57
-
-
Save lhitchon/4615988 to your computer and use it in GitHub Desktop.
Standalone ruby 1.9 app that uses redis
This file contains hidden or 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
source 'https://rubygems.org' | |
gem 'rake' | |
gem 'redis' | |
gem 'cf-runtime' | |
This file contains hidden or 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
--- | |
applications: | |
.: | |
name: sa-redis | |
framework: | |
name: standalone | |
info: | |
mem: 64M | |
description: Standalone Application | |
exec: | |
runtime: ruby193 | |
command: PATH="/opt/cloudfoundry/runtimes/ruby-1.9.3-p125/bin:$PATH" bundle exec rake foo:bar | |
infra: aws | |
url: | |
mem: 128M | |
instances: 1 | |
services: | |
standalone: | |
type: redis |
This file contains hidden or 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
require 'redis' | |
require 'cfruntime/redis' | |
def redisConnection | |
redis_names = CFRuntime::CloudApp.service_names_of_type('redis') | |
redis_options = {} | |
unless redis_names.empty? | |
redis_options = CFRuntime::RedisClient.options_for_svc(redis_names.first) | |
end | |
puts "Redis connection options:" | |
puts redis_options | |
Redis.new(redis_options) | |
end | |
namespace :foo do | |
task :bar do | |
redis = redisConnection | |
loop do | |
puts "#{Time.now} #{RUBY_VERSION}" | |
puts redis.keys.join(', ') | |
sleep 5 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment