Skip to content

Instantly share code, notes, and snippets.

@chapel
Created December 10, 2010 11:23
Show Gist options
  • Save chapel/736101 to your computer and use it in GitHub Desktop.
Save chapel/736101 to your computer and use it in GitHub Desktop.
function stats(col, rand) {
if (!statStore[col]) {
db.get(col+'-stats', function(err, data){
if (err) var data = {}
else data = JSON.parse(data)
if (data[rand]) data[rand]++
else data[rand] = 1
statStore[col] = data
setInterval(db.set(col+'-stats', JSON.stringify(statStore[col]), function(err){
statStore[col] = false
if (err) console.log('Error setting stats for '+req.params.col)
}), 10*1000)
})
} else {
var data = statStore[col]
if (data[rand]) data[rand]++
else data[rand] = 1
statStore[col] = data
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment