Question
What is a best practice to pass an array of objects into Lua script? Is there any better way than converting objects to JSON and parse them with cjson
within a script?
More context
I have streaming application which keeps it state in Redis. Every second we get 5-100 events, all operations are done within single transaction in order to boost performance like following:
RedisCommands<String, String> cmd = getOrCreateRedisClient();
cmd.multi();
for (Event event: listOfEvents) {
cmd.sadd("users", event.getUserId());
cmd.sadd("actions", event.getActionId());
cmd.incrbyfloat("users:" + event.getUserId(), event.getImpact());
}
cmd.exec();
Now I have to move this logic to Lua scripts. I suppose it also will be faster to pass an array of events to Lua script instead of making up to 100 script invocations (one per event). Am I right? What is the best way to pass list of events to Lua script?