I've started to research and play a bit with lua and have found it to be great when wanting to grab ranges of keys. Ex:
business:5:visits:2013-11-12
business:5:visits:2013-11-13
etc
With lua I only have to send one command to redis instead of the complete range of dates.
Now I'm thinking about converting more of our logic and move it onto Redis.
Take our message storing process which currently looks like this:
// create a new unique id
redisClient.incr(Config.messageId, function(err, reply) {
var messageId = reply.toString();
var timestmp = Date.now();
// push message
redisClient.zadd(Config.history + ':' + obj.uid + ':' + obj.channel.replace(/\s+/g, ''), timestmp, messageId);
// store the message data by messageId
redisClient.hmset(Config.messageHash + ':' + messageId, {
'user_id': obj.uid,
'text_body': "some text",
'text_date': timestmp,
});
// set expires
redisClient.expire(Config.history + ':' + obj.uid + ':' + obj.channel.replace(/\s+/g, ''), Config.messageExpire);
redisClient.expire(Config.messageHash + ':' + messageId, Config.messageExpire);
// add to mysql-sync queue
redisClient.RPUSH(Config.messageMySQLSyncQueue, Config.messageHash + ':' + messageId);
});
The above could easily be converted into lua, but is it worth it for performance?
Would it be faster to write this in Lua instead and only have to issue 1 command to Redis? Would it cause problems with blocking other commands?