-
Notifications
You must be signed in to change notification settings - Fork 987
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
Why bitField offset argument is int type? #2964
Comments
Apologies for the late reply on this topic. Could you please share the exact code that lead to this issue? A minimum reproducible example would be perfect! I am not exactly sure which code path you are following and could not give a good answer whether this is a bug or not. |
Thanks for your reply. RedisCommands<String, String> redis;
redis.bitfield("TEST_KEY", BitFieldArgs.Builder.set(unsigned(1), Integer.MAX_VALUE, 1)); // success
redis.bitfield("TEST_KEY", BitFieldArgs.Builder.set(unsigned(1), 4294967295, 1)); // compile failed because 4294967295 is (1 << 32) - 1. It cannot be compiled because the offset parameter (second paramter) type of
|
Oh, I get the problem now, thank you for clarifying. The problem is that ...
I was confused by the mention of Since Java 1.8 the Integer class is able to hold unsigned i32 values so I believe we need to change from |
Yeah, that's right. Although the doc says that Integer x = 4294967295; // cannot compile
Integer y = Integer.parseUnsignedInt("4294967295"); // y = -1
// We should calculate the number over Integer.MAX_VALUE with the minus value. I think it's more complicated and harder to use. Is it better to declare it as long, and validate it before processing? |
I assume that the offset is something you are handling as There is multiple ways you can convert from long to unsigned int: int unsigned = Long.valueOf(4294967295L).intValue();
int anotherUnsigned = (int) 4294967295L;
// etc ...
int maxInt = Integer.MAX_VALUE;
System.out.println("value: " + Integer.toUnsignedString(unsigned) +
" is " + (Integer.compareUnsigned(unsigned, maxInt) > 0 ? " greater" : " smaller") +
" than " + maxInt); Basically the My suggestion to keep the argument as Using
But this is also an option. What do you think? |
Also - another thing - if we use the |
Ah, I understand it and I agree with you. Good explanation! |
It would be much appreciated! Should be a fairly easy change - I would focus the main change on the part of the code that translates the You can start by extending one of the tests in the (make sure you call Let me know if you need any more help and thanks for working on this! |
Pushing this for 6.6.0 for now, as we want 6.5.1 released in December with some critical fixes |
Feature Request
Is your feature request related to a problem? Please describe
I have an issue when I try to do bitfield with set subcommands.
But, when I pass offset argument with a long value, it emits an error with message,
When I pass integer value offset, it succeeds.
I can pass a long value offset with redis-cli, but is there any reason for lettuce to declare offset with int type?
Describe the solution you'd like
BitFieldArgs Offset inner classes declare the offset field with int type. (BitFieldArgs.java)
Maybe, we can just change the offset type to long. But, we should limit the offset value to 512 MB.
The text was updated successfully, but these errors were encountered: