Skip to content

Add support for new BITOP operations: DIFF, DIFF1, ANDOR, ONE #3690

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ofekshenawa
Copy link

Summary

This PR adds support for four new BITOP operations that will be available in Redis 8.2+: DIFF, DIFF1, ANDOR, and ONE. These operations extend Redis bitmap functionality to support common set operations that previously required multiple commands or Lua scripts.

New Operations

BITOP DIFF: Returns members of the first bitmap that are not members of any other bitmaps (X ∧ ¬(Y1 ∨ Y2 ∨ ...))
BITOP DIFF1: Returns members of any bitmap except the first that are not members of the first bitmap (¬X ∧ (Y1 ∨ Y2 ∨ ...))
BITOP ANDOR: Returns members of the first bitmap that are also members of one or more other bitmaps (X ∧ (Y1 ∨ Y2 ∨ ...))
BITOP ONE: Returns members of exactly one of the given bitmaps (generalized XOR for multiple keys)

Changes Made

Tests: Added comprehensive test coverage for all four new operations
Synchronous tests in tests/test_commands.py
Asynchronous tests in tests/test_asyncio/test_commands.py
Tests include bitwise logic verification, edge cases, and return value validation
All tests gated with @skip_if_server_version_lt("8.2.0") for compatibility

@ofekshenawa ofekshenawa marked this pull request as ready for review July 3, 2025 08:56
@ofekshenawa ofekshenawa requested a review from petyaslavova July 3, 2025 08:57
@@ -879,6 +879,103 @@ async def test_bitop_string_operands(self, r: redis.Redis):
assert int(binascii.hexlify(await r.get("res2")), 16) == 0x0102FFFF
assert int(binascii.hexlify(await r.get("res3")), 16) == 0x000000FF

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("8.2.0")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server still returns 8.1.xxx as server version, and those new tests will be skipped. I suggest to define this rule as @skip_if_server_version_lt("8.1.224"). It can be updated later, when server version is update.

@petyaslavova petyaslavova added the maintenance Maintenance (CI, Releases, etc) label Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance (CI, Releases, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants