I am trying to run a Lua script from lettuce like this that does an hgetall command on a remote Redis:
private static String SCRIPT_CONS = "local hgetallkeys = function(key)" +"\n" +
"local flat_map = redis.call('HGETALL', KEYS[1], ARGV[1])" +"\n" +
"return flat_map"+"\n" +
"end"+"\n";
RedisHelper.testEval(SCRIPT_CONS,"some.key");
class RedisHelper
{
public static String testScriptLoad(String SCRIPT_CONS) {
CompletableFuture<String> future = connectionPool.getPool().acquire().thenCompose(con ->
con.async().scriptLoad(SCRIPT_CONS));
return RedisFuturesHelper.getOrTimeout(future);
}
public static List<String> testEval(String SCRIPT_CONS, String key) {
String script = testScriptLoad(SCRIPT_CONS);
CompletableFuture<List<String>> list = connectionPool.getPool().acquire().thenCompose(con ->
con.async().evalsha(script, ScriptOutputType.MULTI,new String[0], key));
return RedisFuturesHelper.getOrTimeout(list);
}
}
While running it, I turned on Monitor on redis-cli prompt I see this:
1710871181.580705 [0 127.0.0.1:50312] "SCRIPT" "LOAD" "local hgetallkeys = function(key)\nlocal flat_map = redis.call('HGETALL', KEYS[1], ARGV[1])\nreturn flat_map\nend\n"
1710871181.591642 [0 127.0.0.1:50316] "EVALSHA" "e3949eaf6e1dec1d920fc3f3d948d3e49af714ca" "0" "some.key"
When I manually try to run this digest I get this:
127.0.0.1:6379> "EVAL" "e3949eaf6e1dec1d920fc3f3d948d3e49af714ca" "1" "hdm.usp.device.info:496"
(error) ERR Error compiling script (new function): user_script:2: '=' expected near 'end'
127.0.0.1:6379>
Please help with syntax here.
I tried changing SCRIPT_CONS in many ways, but not able to get that right.