Skip to content

Instantly share code, notes, and snippets.

@lhitchon
Created January 23, 2013 23:57
Show Gist options
  • Save lhitchon/4615988 to your computer and use it in GitHub Desktop.
Save lhitchon/4615988 to your computer and use it in GitHub Desktop.
Standalone ruby 1.9 app that uses redis
source 'https://rubygems.org'
gem 'rake'
gem 'redis'
gem 'cf-runtime'
---
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
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