Created
August 14, 2011 13:14
-
-
Save mythz/1144866 to your computer and use it in GitHub Desktop.
Create and increment multiple counters with express, coffeescript and redis
This file contains 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
#1. install node, npm and coffeescript | |
#2. >npm install express | |
#3. >npm install node_redis | |
#4. >npm install -d | |
redis = require('redis').createClient() | |
redis.on 'error', (err) -> console.log "Redis connection error to #{redis.host} : #{redis.port} - #{err}" | |
app = require('express').createServer() | |
#create and increment multiple counters in redis, via: http://localhost:3000/counters/my-counter | |
app.get '/counters/:id', (request, response) -> | |
id = request.params.id | |
redis.incr id, (err, val) -> | |
response.send "#{id}: #{val}", 'Content-Type': 'text/plain', 201 | |
app.listen 3000 | |
console.log "Express server listening on port #{app.address().port}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment