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

Support BIT/BYTE for bitcount and bitpos for redis 7+ #1242

Merged
merged 1 commit into from
Dec 9, 2023

Conversation

fatkodima
Copy link
Contributor

@fatkodima fatkodima commented Dec 9, 2023

Reference #1187

Redis 7.0 release notes - https://raw.githubusercontent.com/redis/redis/7.0/00-RELEASENOTES

I am not very happy with the bytes_range parameter name. Maybe you can suggest something better? Maybe use_bytes or offset_unit etc...

@byroot
Copy link
Collaborator

byroot commented Dec 9, 2023

What about: scale: :bit or index: :byte?

@fatkodima fatkodima force-pushed the bitcount-bitpos-add-bits-unit branch from 9c6af45 to d04583b Compare December 9, 2023 14:19
@fatkodima
Copy link
Contributor Author

👍 for :scale.

@fatkodima fatkodima force-pushed the bitcount-bitpos-add-bits-unit branch from d04583b to 2d0bc45 Compare December 9, 2023 14:22
send_command([:bitcount, key, start, stop])
def bitcount(key, start = 0, stop = -1, scale: 'BYTE')
command = [:bitcount, key, start, stop]
command << 'BIT' if scale.to_s.upcase == 'BIT'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
command << 'BIT' if scale.to_s.upcase == 'BIT'
command << 'BIT' if scale.

I think we should append it unless it's not set. Because here if I pass scale: "lol", it will silently do nothing.

With scale: nil in the signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, thanks.

@fatkodima fatkodima force-pushed the bitcount-bitpos-add-bits-unit branch from 2d0bc45 to 9a6abb4 Compare December 9, 2023 16:25
@@ -27,9 +27,13 @@ def getbit(key, offset)
# @param [String] key
# @param [Integer] start start index
# @param [Integer] stop stop index
# @param [String, Symbol] scale the scale of the offset range
# e.g. 'BYTE' - interpreted as a range of bytes, 'BIT' - interpreted as a range of bites
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# e.g. 'BYTE' - interpreted as a range of bytes, 'BIT' - interpreted as a range of bites
# e.g. 'BYTE' - interpreted as a range of bytes, 'BIT' - interpreted as a range of bits

send_command([:bitcount, key, start, stop])
def bitcount(key, start = 0, stop = -1, scale: nil)
command = [:bitcount, key, start, stop]
command << scale.to_s.upcase if scale
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't even bother with the to_s.upcase, we can directly pass it to redis in lower case, it's no problem.

@fatkodima fatkodima force-pushed the bitcount-bitpos-add-bits-unit branch from 9a6abb4 to df08cd0 Compare December 9, 2023 16:29
@byroot byroot merged commit 935f64f into redis:master Dec 9, 2023
16 of 17 checks passed
@fatkodima fatkodima deleted the bitcount-bitpos-add-bits-unit branch December 9, 2023 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants