jQuery Redis hit counter to track view of cached Rails pages -


i have static cached pages want track hits of , order popularity.

what best way of tracking these views in redis , loading them main database?

right thinking of using jquery this

$.get("/track/", { id: "1234" } ); 

and using redis gem in "track" controller call

redis.incr "1234" 

once day run cron of like

pages.each |p|    p.hits = redis.get(p.id.to_s) end 

here final rake task, in case helps anyone

require 'redis' task :cron => :environment    uri = uri.parse(redis_url)    redis = redis.new(:host => uri.host, :port => uri.port, :password => uri.password)     pages.all.each |p|       views = redis.get(p.id.to_s)       if views           p.hits = p.hits + views.to_i            if p.save              redis.set pid, "0"           end        end    end  end 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -