admin管理员组

文章数量:1389758

Redis func is registered having the body

redis.register_function('eval_resources', function(keys, args)
    return type(args[1]) .. " " .. args[1]
end)

Caller's code

        Object[] argsList = {"123", "abc"};
        String res2 = function.call(
                FunctionMode.WRITE,
                "eval_resources",
                FunctionResult.STRING,
                Collections.emptyList(),
                argsList);

Response I am getting string 12�

Due to this encoding issue, I am not able to parse integer as an input inside Lua script.

I tried removing the end character, still the input cannot be parsed to integer.

redis.register_function('eval_resources', function(keys, args)
    local actual_val = tostring(string.sub(args[1], 1, 2))
    local numericalVal = tonumber(actual_val)
    return type(actual_val) .. " " .. actual_val  .. " type of num ->" .. type(numericalVal)
end)

This is working perfectly with redis-cli.

Redis func is registered having the body

redis.register_function('eval_resources', function(keys, args)
    return type(args[1]) .. " " .. args[1]
end)

Caller's code

        Object[] argsList = {"123", "abc"};
        String res2 = function.call(
                FunctionMode.WRITE,
                "eval_resources",
                FunctionResult.STRING,
                Collections.emptyList(),
                argsList);

Response I am getting string 12�

Due to this encoding issue, I am not able to parse integer as an input inside Lua script.

I tried removing the end character, still the input cannot be parsed to integer.

redis.register_function('eval_resources', function(keys, args)
    local actual_val = tostring(string.sub(args[1], 1, 2))
    local numericalVal = tonumber(actual_val)
    return type(actual_val) .. " " .. actual_val  .. " type of num ->" .. type(numericalVal)
end)

This is working perfectly with redis-cli.

Share Improve this question asked Mar 12 at 20:58 siddharthabhi30siddharthabhi30 608 bronze badges 1
  • lua script worked perfectly too. – siddharthabhi30 Commented Mar 12 at 21:05
Add a comment  | 

1 Answer 1

Reset to default 0

Found the root cause.

Redisson was adding extra characters while encoding https://redisson.pro/docs/data-and-services/data-serialization/?utm_source=chatgpt

Plain text codec works

config.setCodec(new StringCodec());
        config.useSingleServer()
                .setAddress(redisURL)
                .setConnectionPoolSize(30);
        RedissonClient redisson = Redisson.create(config);

本文标签: luaRedisson with Redis function is adding a special character while sending the inputStack Overflow