@@ -882,117 +882,90 @@ async def test_bitop_string_operands(self, r: redis.Redis):
882
882
@pytest .mark .onlynoncluster
883
883
@skip_if_server_version_lt ("8.2.0" )
884
884
async def test_bitop_diff (self , r : redis .Redis ):
885
- """Test BITOP DIFF operation"""
886
- # Set up test data: a=0b11110000, b=0b11000000, c=0b10000000
887
- await r .set ("a" , b"\xf0 " ) # 11110000
888
- await r .set ("b" , b"\xc0 " ) # 11000000
889
- await r .set ("c" , b"\x80 " ) # 10000000
885
+ await r .set ("a" , b"\xf0 " )
886
+ await r .set ("b" , b"\xc0 " )
887
+ await r .set ("c" , b"\x80 " )
890
888
891
- # DIFF: a AND NOT(b OR c) = 11110000 AND NOT(11000000) = 11110000 AND 00111111 = 00110000
892
889
result = await r .bitop ("DIFF" , "result" , "a" , "b" , "c" )
893
- assert result == 1 # Length of result
894
- assert await r .get ("result" ) == b"\x30 " # 00110000
890
+ assert result == 1
891
+ assert await r .get ("result" ) == b"\x30 "
895
892
896
- # Test with non-existent keys
897
893
await r .bitop ("DIFF" , "result2" , "a" , "nonexistent" )
898
- assert await r .get ("result2" ) == b"\xf0 " # Should be same as 'a'
894
+ assert await r .get ("result2" ) == b"\xf0 "
899
895
900
896
@pytest .mark .onlynoncluster
901
897
@skip_if_server_version_lt ("8.2.0" )
902
898
async def test_bitop_diff1 (self , r : redis .Redis ):
903
- """Test BITOP DIFF1 operation"""
904
- # Set up test data: a=0b11110000, b=0b11000000, c=0b10000000
905
- await r .set ("a" , b"\xf0 " ) # 11110000
906
- await r .set ("b" , b"\xc0 " ) # 11000000
907
- await r .set ("c" , b"\x80 " ) # 10000000
899
+ await r .set ("a" , b"\xf0 " )
900
+ await r .set ("b" , b"\xc0 " )
901
+ await r .set ("c" , b"\x80 " )
908
902
909
- # DIFF1: NOT(a) AND (b OR c) = NOT(11110000) AND (11000000) = 00001111 AND 11000000 = 00000000
910
903
result = await r .bitop ("DIFF1" , "result" , "a" , "b" , "c" )
911
- assert result == 1 # Length of result
912
- assert await r .get ("result" ) == b"\x00 " # 00000000
904
+ assert result == 1
905
+ assert await r .get ("result" ) == b"\x00 "
913
906
914
- # Test with different data where result is non-zero
915
- await r .set ("d" , b"\x0f " ) # 00001111
916
- await r .set ("e" , b"\x03 " ) # 00000011
917
- # DIFF1: NOT(d) AND e = NOT(00001111) AND 00000011 = 11110000 AND 00000011 = 00000000
907
+ await r .set ("d" , b"\x0f " )
908
+ await r .set ("e" , b"\x03 " )
918
909
await r .bitop ("DIFF1" , "result2" , "d" , "e" )
919
910
assert await r .get ("result2" ) == b"\x00 "
920
911
921
912
@pytest .mark .onlynoncluster
922
913
@skip_if_server_version_lt ("8.2.0" )
923
914
async def test_bitop_andor (self , r : redis .Redis ):
924
- """Test BITOP ANDOR operation"""
925
- # Set up test data: a=0b11110000, b=0b11000000, c=0b10000000
926
- await r .set ("a" , b"\xf0 " ) # 11110000
927
- await r .set ("b" , b"\xc0 " ) # 11000000
928
- await r .set ("c" , b"\x80 " ) # 10000000
915
+ await r .set ("a" , b"\xf0 " )
916
+ await r .set ("b" , b"\xc0 " )
917
+ await r .set ("c" , b"\x80 " )
929
918
930
- # ANDOR: a AND (b OR c) = 11110000 AND (11000000) = 11110000 AND 11000000 = 11000000
931
919
result = await r .bitop ("ANDOR" , "result" , "a" , "b" , "c" )
932
- assert result == 1 # Length of result
933
- assert await r .get ("result" ) == b"\xc0 " # 11000000
920
+ assert result == 1
921
+ assert await r .get ("result" ) == b"\xc0 "
934
922
935
- # Test with non-overlapping bits
936
- await r .set ("x" , b"\xf0 " ) # 11110000
937
- await r .set ("y" , b"\x0f " ) # 00001111
923
+ await r .set ("x" , b"\xf0 " )
924
+ await r .set ("y" , b"\x0f " )
938
925
await r .bitop ("ANDOR" , "result2" , "x" , "y" )
939
- assert await r .get ("result2" ) == b"\x00 " # No overlap
926
+ assert await r .get ("result2" ) == b"\x00 "
940
927
941
928
@pytest .mark .onlynoncluster
942
929
@skip_if_server_version_lt ("8.2.0" )
943
930
async def test_bitop_one (self , r : redis .Redis ):
944
- """Test BITOP ONE operation"""
945
- # Set up test data: a=0b11110000, b=0b11000000, c=0b10000000
946
- await r .set ("a" , b"\xf0 " ) # 11110000
947
- await r .set ("b" , b"\xc0 " ) # 11000000
948
- await r .set ("c" , b"\x80 " ) # 10000000
949
-
950
- # ONE: bits set in exactly one key
951
- # Position analysis:
952
- # Bit 7: a=1, b=1, c=1 -> count=3 -> not included
953
- # Bit 6: a=1, b=1, c=0 -> count=2 -> not included
954
- # Bit 5: a=1, b=0, c=0 -> count=1 -> included
955
- # Bit 4: a=1, b=0, c=0 -> count=1 -> included
956
- # Expected result: 00110000 = 0x30
931
+ await r .set ("a" , b"\xf0 " )
932
+ await r .set ("b" , b"\xc0 " )
933
+ await r .set ("c" , b"\x80 " )
934
+
957
935
result = await r .bitop ("ONE" , "result" , "a" , "b" , "c" )
958
- assert result == 1 # Length of result
959
- assert await r .get ("result" ) == b"\x30 " # 00110000
936
+ assert result == 1
937
+ assert await r .get ("result" ) == b"\x30 "
960
938
961
- # Test with two keys (should be equivalent to XOR)
962
- await r .set ("x" , b"\xf0 " ) # 11110000
963
- await r .set ("y" , b"\x0f " ) # 00001111
939
+ await r .set ("x" , b"\xf0 " )
940
+ await r .set ("y" , b"\x0f " )
964
941
await r .bitop ("ONE" , "result2" , "x" , "y" )
965
- assert await r .get ("result2" ) == b"\xff " # 11111111 (XOR result)
942
+ assert await r .get ("result2" ) == b"\xff "
966
943
967
944
@pytest .mark .onlynoncluster
968
945
@skip_if_server_version_lt ("8.2.0" )
969
946
async def test_bitop_new_operations_with_empty_keys (self , r : redis .Redis ):
970
- """Test new BITOP operations with empty/non-existent keys"""
971
- await r .set ("a" , b"\xff " ) # 11111111
947
+ await r .set ("a" , b"\xff " )
972
948
973
- # Test with empty destination
974
949
await r .bitop ("DIFF" , "empty_result" , "nonexistent" , "a" )
975
- assert await r .get ("empty_result" ) is None
950
+ assert await r .get ("empty_result" ) == b" \x00 "
976
951
977
952
await r .bitop ("DIFF1" , "empty_result2" , "a" , "nonexistent" )
978
- assert await r .get ("empty_result2" ) is None
953
+ assert await r .get ("empty_result2" ) == b" \x00 "
979
954
980
955
await r .bitop ("ANDOR" , "empty_result3" , "a" , "nonexistent" )
981
- assert await r .get ("empty_result3" ) is None
956
+ assert await r .get ("empty_result3" ) == b" \x00 "
982
957
983
958
await r .bitop ("ONE" , "empty_result4" , "nonexistent" )
984
959
assert await r .get ("empty_result4" ) is None
985
960
986
961
@pytest .mark .onlynoncluster
987
962
@skip_if_server_version_lt ("8.2.0" )
988
963
async def test_bitop_new_operations_return_values (self , r : redis .Redis ):
989
- """Test that new BITOP operations return correct length values"""
990
- await r .set ("a" , b"\xff \x00 \xff " ) # 3 bytes
991
- await r .set ("b" , b"\x00 \xff " ) # 2 bytes
964
+ await r .set ("a" , b"\xff \x00 \xff " )
965
+ await r .set ("b" , b"\x00 \xff " )
992
966
993
- # All operations should return the length of the result string
994
967
result1 = await r .bitop ("DIFF" , "result1" , "a" , "b" )
995
- assert result1 == 3 # Length of longest input
968
+ assert result1 == 3
996
969
997
970
result2 = await r .bitop ("DIFF1" , "result2" , "a" , "b" )
998
971
assert result2 == 3
0 commit comments