How to return multiple results from a LUA script

There are many ways of returning multiple results by executing a lua script. You can return list of results. In my case I was only interested in 2 results, so I used string concatenation separated by a space. So here is the snippet from code which I have written. It is using jedis client to communicate with redis server using lua script

String script1 = “local s1 =‘hget’,'” + cacheKey + SEMI_COLON + REDISSTATS_CACHE_PROPERTIES + “‘,'” + PROP_MAXELEMENTSINMEMORY + “‘)”; String script2 = “local s2 =‘hget’,'” + cacheKey + “‘,'” + REDISSTATS_CACHE_CURRENTCOUNT + “‘)”;   String fullScript = script1 + ” ” + script2 + “if(s1 == false) then s1 =’null’ end if(s2 ==false) then s2 = ‘null’ end return s2 .. ‘ ‘ .. s1”; cacheMgr.eval(fullScript);

So am executing to redis calls , storing them in variables s1 and s2, concatenatin s1 and s2 and finally returning the conctaenated result. In my java class I will obviously split the result.

Leave a Reply

Your email address will not be published. Required fields are marked *