Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Fasted way to increment a persistent counter from a node.js app?

Fasted way to increment a persistent counter from a node.js app?

Problem

I have a search engine written in node.js/express that is currently not logging any statistics, and I'd like to start keeping track of # of queries per day. So I just need a persistent counter that I can increment each time a query is submitted. (I'll write a cron job to store it and clear it out at the end of the day, that's not relevant to this question).

There are obviously many ways to do this, so my one requirement is that it be very fast. Is redis overkill for this? Is there a simpler solution that would still be very fast?

Problem courtesy of: Mike Crittenden

Solution

Literally fastest solution is using Memcache.

Create a counter object which has counters for each query, e.g.

counter = {
  '_q:whatever': 1,
  '_q:something else': 123
}

Then on page load add or increment keys in Counter. And then using cron pull Counter and parse all keys, update in your DB.

Solution courtesy of: mvbl fst

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Fasted way to increment a persistent counter from a node.js app?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×