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

Eval lua script expects return integer but null #2200

Closed
CodePlayer opened this issue Sep 21, 2022 · 2 comments
Closed

Eval lua script expects return integer but null #2200

CodePlayer opened this issue Sep 21, 2022 · 2 comments
Labels
type: bug A general bug
Milestone

Comments

@CodePlayer
Copy link

CodePlayer commented Sep 21, 2022

Bug Report

Current Behavior

There is a string key named a, which value is 1 in Redis.
I want to read the value as Long by lua script.
However, it returns null unexpectedlly.

Input Code

// code example
final RedisCommands<String, String> redisCommands = redisClient.connect().sync();
redisCommands.set("a", "1"); // SET a 1

String luaScript = "return redis.call('GET', KEYS[1])";
Long val = redisCommands.eval(luaScript, ScriptOutputType.INTEGER, "a");
System.out.println(val); // expect output "1" but "null"

Expected behavior/code

return 1 as expected ( OR maybe throw exception ) . Does NOT return null silently.

Environment

  • Lettuce version(s): 6.1.9.RELEASE
  • Redis version: 6.0.14

Possible Solution

Enhance type conversion compatibility. Throw an exception when the types are still not compatible.

Additional context

BTW, Redisson client works well in same situation.

@mp911de mp911de added the type: bug A general bug label Sep 26, 2022
@mp911de mp911de added this to the 6.2.1.RELEASE milestone Sep 26, 2022
@mp911de
Copy link
Collaborator

mp911de commented Sep 26, 2022

Thanks for the report. It is indeed unfortunate that we silently fall back to null. The offending piece of code is quite old, so let's see what happens if we fix that.

mp911de added a commit that referenced this issue Sep 26, 2022
…eturned script return type does not match #2200

We now attempt a best-effort conversion for return values for which the intended CommandOutput does not match. Specifically, Boolean and Integer outputs attempt return value parsing.
mp911de added a commit that referenced this issue Sep 26, 2022
…eturned script return type does not match #2200

We now attempt a best-effort conversion for return values for which the intended CommandOutput does not match. Specifically, Boolean and Integer outputs attempt return value parsing.
@mp911de
Copy link
Collaborator

mp911de commented Sep 26, 2022

We now attempt best-effort parsing. In your example, the return value is a String ("1") and not an Integer. We no longer fall silently back to null.

@mp911de mp911de closed this as completed Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants