lua Blogs
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
Kiprosh is now part of LawLytics
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
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 -
What is Redis ? We all might be familiar with [Redis][1] . For those who are not - It's a "NoSQL" key-value data store. More precisely, it is a data structure server. To read more - [Redis-Wiki][2] Do [try redis][3] it has a nice interactive tutorial. To install and setup redis on your machine see [how-to-install-and-use-redis][4] What is LUA ? LUA is an embeddable scripting language. About LUA - http://www.lua.org/about.html Redis >= 2.6 supports embedded scripting language. Lets give a try to it. To run a script in redis we need