You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently BitFieldSubCommands supports redis bitfiled operations by chaining methods to generate multiple subcomamnd, as follows.
BitFieldSubCommandsfieldSubCommands = 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 = newlong[]{1,3,5,7,9};
BitFieldSubCommandsfieldSubCommands = BitFieldSubCommands.create();
for (inti = 0; i < offsetArray.length; i++) {
BitFieldSubCommandssubCommands = 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 = newlong[]{1,3,5,7,9};
List<BitFieldSubCommands.BitFieldSubCommand> list = newArrayList<>();
for (inti = 0; i < offsetArray.length; i++) {
BitFieldSubCommands.BitFieldGetbitFieldGet = newBitFieldSubCommands.BitFieldGet(BitFieldSubCommands.BitFieldType.unsigned(1),offsetArray[i]);
list.add(bitFieldGet);
}
BitFieldSubCommandsfieldSubCommands = newBitFieldSubCommands(list);
List<Long> result = redisTemplate.opsForValue().bitField("test",fieldSubCommands);
Currently
BitFieldSubCommands
supports redisbitfiled
operations by chaining methods to generate multiple subcomamnd, as follows.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
Solution
In order to support such operations as mentioned above in my project, I modified the code related to
BitFieldSubCommands
by liberalizing theBitFieldCommands
andBitFieldCommand
implementation classes such asBitFieldGet
constructor to be public, so that I can freely combine various bit operations in the following example way.See also https://redis.io/commands/bitfield for further information.
The text was updated successfully, but these errors were encountered: