Created
January 1, 2012 12:12
-
-
Save oza/1547175 to your computer and use it in GitHub Desktop.
A sample application from Memcached as a Service for Cloud Fondry
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 '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