Skip to content

feat(cf): add CF.COUNT command - #3650

Open
ChaseForward wants to merge 1 commit into
apache:unstablefrom
ChaseForward:feat-cf-count
Open

ChaseForward wants to merge 1 commit into
apache:unstablefrom
ChaseForward:feat-cf-count

Conversation

@ChaseForward

@ChaseForward ChaseForward commented Sep 27, 2026 •

Copy link
Copy Markdown

Description

This PR adds the CF.COUNT command, bringing RedisBloom compatibility to the cuckoo filter. It returns the number of occurrences of an item in a cuckoo filter by scanning the primary and secondary buckets of every sub-filter. Returns 0 if the filter does not exist.

Related

Split from #3591 as suggested (one command per PR). Builds on the cuckoo filter infrastructure from #3481.

Assisted by glm5.3.

Return the number of occurrences of an item in a cuckoo filter by
scanning the primary and secondary buckets of every sub-filter.
Returns 0 if the filter does not exist.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Hi @ChaseForward,

Thank you for your pull request. Please review our Contributing Guide.

Please make sure you understand your changes and explain your reasoning in this pull request. Low-quality pull requests may be closed.

@nagisa-kunhah nagisa-kunhah left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Totally LGTM, thanks for your contribution!

Additionnally, cam we also add focused C++ tests for the new counting APIs, likes CuckooPageCache::CountInBucket, CuckooSubFilter::Count and CuckooChain::Count?

Comment thread src/commands/cmd_cuckoo_filter.cc
Comment on lines +113 to +117
if (bucket1_idx != bucket2_idx) {
s = pages_.CountInBucket(filter_index_, num_buckets_, bucket2_idx, fingerprint, &c2);
if (!s.ok()) return s;
*count += c2;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Referring to the RedisBloom implementation: https://github.com/RedisBloom/RedisBloom/blob/a89aac8e75da4a1fbbb59a307ea2f3b4ae87870d/src/cuckoo.c#L197 , when bucket1_idx == bucket2_idx, RedisBloom may count the item twice. Should we follow RedisBloom's semantics? cc @jihuayu

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is a bug in RedisBloom, and we don't need to follow its behavior.

@jihuayu

jihuayu commented Sep 28, 2026

Copy link
Copy Markdown
Member

Hi @ChaseForward Can you resolved the conficts. Thanks

@ChaseForward

Copy link
Copy Markdown
Author

Thanks for your review and suggestion. I plan to complete these unit tests during the National Day holiday. My apologies for the prolonged delay.

Comment on lines +162 to +166
/* Register commands
CF.RESERVE
CF.ADD
CF.COUNT
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove this.

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.

4 participants