Skip to content

Instantly share code, notes, and snippets.

@oza
Created January 1, 2012 12:12
Show Gist options
  • Save oza/1547175 to your computer and use it in GitHub Desktop.
Save oza/1547175 to your computer and use it in GitHub Desktop.
A sample application from Memcached as a Service for Cloud Fondry
require 'sinatra'
require 'dalli'
require 'json'
get '/count' do
res = ''
services = JSON.parse(ENV['VCAP_SERVICES'])
credentials = services["memcached-1.4.10"].first["credentials"]
host = credentials['host']
port = credentials['port'].to_s
hostname = host + ":" + port
dc = Dalli::Client.new(hostname)
cnt = dc.get("cnt")
if cnt
dc.cas("cnt", 1) {|c| dc.set("cnt", c+1) }
else
dc.set("cnt", 1)
end
res << credentials.to_s
res << '<font size="128">' + cnt.to_s + '</font>'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment