Skip to content

Add support for BitFieldSubCommands that generate multiple bit operations using non-chaining methods #2055

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

Closed
Yanam opened this issue Apr 27, 2021 · 0 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@Yanam
Copy link
Contributor

Yanam commented Apr 27, 2021

Currently BitFieldSubCommands supports redis bitfiled operations by chaining methods to generate multiple subcomamnd, as follows.

    BitFieldSubCommands fieldSubCommands = BitFieldSubCommands.create()
            .get(BitFieldSubCommands.BitFieldType.unsigned(1)).valueAt(1)
            .get(BitFieldSubCommands.BitFieldType.unsigned(1)).valueAt(2);

    List<Long> result = redisTemplate.opsForValue().bitField("test", fieldSubCommands);

Problem

However, the bitmap offset to be manipulated in the actual project is generated upstream by some rules, and it is not possible to directly use the above chain method to generate multiple bit fields for the operation of the command

    // The offset data is usually obtained through the upstream method 
    // long[] offsetArray = getBitIndex();
    long[] offsetArray = new long[]{1,3,5,7,9};
    BitFieldSubCommands fieldSubCommands = BitFieldSubCommands.create();
    for (int i = 0; i < offsetArray.length; i++) {
            BitFieldSubCommands subCommands = BitFieldSubCommands.create.get(BitFieldSubCommands.BitFieldType.unsigned(1)).valueAt(offsetArray[i]);
            //There is no way to combine multiple commands
    }
   
    List<Long> result = redisTemplate.opsForValue().bitField("test",fieldSubCommands);

Solution

In order to support such operations as mentioned above in my project, I modified the code related to BitFieldSubCommands by liberalizing the BitFieldCommands and BitFieldCommand implementation classes such as BitFieldGet constructor to be public, so that I can freely combine various bit operations in the following example way.

    long[] offsetArray = new long[]{1,3,5,7,9};

    List<BitFieldSubCommands.BitFieldSubCommand> list = new ArrayList<>();

    for (int i = 0; i < offsetArray.length; i++) {
            BitFieldSubCommands.BitFieldGet bitFieldGet = new BitFieldSubCommands.BitFieldGet(BitFieldSubCommands.BitFieldType.unsigned(1),offsetArray[i]);

            list.add(bitFieldGet);
    }
    BitFieldSubCommands fieldSubCommands = new BitFieldSubCommands(list);
    List<Long> result = redisTemplate.opsForValue().bitField("test",fieldSubCommands);

See also https://redis.io/commands/bitfield for further information.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 27, 2021
@mp911de mp911de self-assigned this May 3, 2021
mp911de pushed a commit that referenced this issue Jun 17, 2021
…ions using non-chaining methods.

Original pull request: #2060.
Closes #2055
mp911de added a commit that referenced this issue Jun 17, 2021
Add since tags, equals/hashCode/toString methods. Reformat code.

Original pull request: #2060.
Closes #2055
mp911de added a commit that referenced this issue Jun 17, 2021
Add since tags, equals/hashCode/toString methods. Reformat code.

Original pull request: #2060.
Closes #2055
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 17, 2021
@mp911de mp911de added this to the 2.5.2 (2021.0.2) milestone Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
3 participants