Skip to content

Instantly share code, notes, and snippets.

@puma007
Forked from oza/counter.rb
Created March 10, 2013 14:26
Show Gist options
  • Save puma007/5128769 to your computer and use it in GitHub Desktop.
Save puma007/5128769 to your computer and use it in GitHub Desktop.
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