Quick Tips for Programming

I thought to create a quick tip post which is kind of lesson learnt, so that every time I learn something can add here and which could help others too. These examples here are not something I have created to support the points which I have mentioned below. Whereas these are the real code snippets of a project. Where team has written code in this manner and given feedback to improve their code. So I thought it would be better if I write a Lesson learnt post which could help other to be aware of mistake they can make while

Example usage of Redis - LUA script in Rails

This topic is about using Redis and LUA script in Rails. Before proceeding, you may like to read [ Introduction to LUA script with Redis][1] Redis doesn't have any command to calculate total number of keys We'll use [zrangebyscore][2] to find number of members between index range. Instal [redis-rb][3] Start rails console Prepare a dataset based on timestamp > t10 = 10.minutes.ago => 1386935151 > t20 = 20.minutes.ago => 1386934568 > t30 = 30.minutes.ago => 1386933971 > t40 = 40.minutes.ago => 1386933374 This is non-realistic data, may vary for you. Populate redis with Sorted Set > redis = Redis.new # initialize redis => # zadd -