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

Bitmaps not interchangeable with strings #520

Closed
newacct opened this issue Sep 8, 2024 · 4 comments · Fixed by #547
Closed

Bitmaps not interchangeable with strings #520

newacct opened this issue Sep 8, 2024 · 4 comments · Fixed by #547
Labels

Comments

@newacct
Copy link

newacct commented Sep 8, 2024

The documentation page for SETBIT has an example:

SETBIT bitmapsarestrings 2 1
SETBIT bitmapsarestrings 3 1
SETBIT bitmapsarestrings 5 1
SETBIT bitmapsarestrings 10 1
SETBIT bitmapsarestrings 11 1
SETBIT bitmapsarestrings 14 1
GET bitmapsarestrings

which should produce the string 42, but it instead produces [��sr1com.github.fppt.jedismock.datastructures.RMBitMapIsizeLbitSettLjava/util/BitSet;xr9com.github.fppt.jedismock.datastructures.StringCompatible0����psrjava.util.BitSetn��~94�![bitst[Jxpur[Jx ��u�xpL,x]

Also, when you set a string and then get the bits, it produces the wrong result:

SET foo e
GETBIT foo 0

should produce 0 (bit 0 is the most significant bit, not the least significant bit), but produces 1.

@inponomarev
Copy link
Collaborator

inponomarev commented Sep 11, 2024

Hey @newacct , first of all, enormous thank you for submitting all the bugs for JedisMock!

This one is a known limitation, as in order to hold a value which is modified by SETBIT operations, Java's BitSet structure is used instead of String.

In Java's BitSet all the bit operations are implemented reliably and efficiently. My original hypothesis was that it is unlikely that users will be using bit-operations on data which is treated as strings at the same time(Bloom filters being the main use case for Redis' bitsets). So in JedisMock Strings and BitSets are different datatypes (similar to strings and sets) -- unlike in "real" Redis.

Could you clarify if you have a real-life use-case for this or is this just a random finding of yours?

@newacct
Copy link
Author

newacct commented Sep 11, 2024

We are thinking of maybe using jedis-mock in place of Redis for our unit tests once all the bugs have been ironed out, but we would disable it for unit tests that use unsupported features. There is one place in the code that tests setting bits and getting the whole bitmap out to parse, but if this is a known limitation, then that's fine; we'll just not use jedis-mock for that.

@inponomarev
Copy link
Collaborator

Got it. Yes it's a limitation, but not an unsurmountable one. I just thought that there are no real-world scenarios when you would like to set bits and then read the result as a meaningful string (reading it as a "data dump" which can be stored later somwhere else is supported). But yeah, as soon as there's evidence that people are doing this, we're going to fix it, although this will take a couple of months maybe.

The fix for unpack() is ready btw and is going to be released very soon.

@inponomarev
Copy link
Collaborator

Fixed in 1.1.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants