Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommandMapper doesn't affect Lua scripts #5797

Open
vatrubin opened this issue Apr 19, 2024 · 0 comments
Open

CommandMapper doesn't affect Lua scripts #5797

vatrubin opened this issue Apr 19, 2024 · 0 comments
Labels

Comments

@vatrubin
Copy link

Even though I used a CommandMapper , I get errors like

Error from log
org.redisson.client.RedisException: ERR Error running script (call to f_6866459238a13a701d42f4971f12d9f3a50e2442): @user_script:1: @user_script: 1: Unknown Redis command called from Lua script. channel: [id: 0x53553a07, L:/127.0.0.1:55909 - R:localhost/127.0.0.1:6379] command: (EVAL), promise: java.util.concurrent.CompletableFuture@3b7a5b6f[Not completed], params: [local val = redis.call('get', KEYS[3]); if val ~= false then return tonumber(val);end; if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); redis.call('set', KEYS[3], 0, 'px', ARGV[5]); return 0; else redis.call('del', KEYS[1]); redis.call(ARGV[4], KEYS[2], ARGV[1]); redis.call('set', KEYS[3], 1, 'px', ARGV[5]); return 1; end; , 3, distributedCacheLock, redisson_lock__channel:{distributedCacheLock}, redisson_unlock_latch:{distributedCacheLock}:4dc80af0fa2237fb917092777d0fe2a5, 0, 30000, 2164461e-f913-442f-8aa3-224fb34e63bf:1, PUBLISH, 120000]
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:381)
	at org.redisson.client.handler.CommandDecoder.decodeCommandBatch(CommandDecoder.java:279)
	at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:217)
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:144)

I would like CommandMapper had a method String mapScript(String script) that would be called in CommandAsyncService in methods syncedEval and evalAsync

I would be able to implement such a mapper:

public class MyCommandMapper implements CommandMapper {

  Map<String, String> commandMap;

  public MyCommandMapper (Map<String, String> commandMap) {
    this.commandMap = ImmutableMap.copyOf(commandMap);
  }

  @Override
  public String map(String name) {
    return commandMap.getOrDefault(name, name);
  }

  public String mapScript(String script) {
    for (Map.Entry<String, String> commandMapEntry : commandMap.entrySet()) {
      String oldName = commandMapEntry.getKey();
      String newName = commandMapEntry.getValue();
      script = script.replace("'" + oldName.toLowerCase() + "'", "'" + newName.toLowerCase() + "'");
    }
    return script;
  }
}
@mrniko mrniko added the bug label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants