Skip to content

DOC: clarify BITPOS behavior on non-existent vs empty keys - #4282

Merged
dwdougherty merged 1 commit into
redis:mainfrom
itsMathew:docs/bitpos-non-existent-empty-key-clarification
Oct 16, 2026
Merged

dwdougherty merged 1 commit into
redis:mainfrom
itsMathew:docs/bitpos-non-existent-empty-key-clarification

Conversation

@itsMathew

@itsMathew itsMathew commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes redis/redis#15987

The BITPOS documentation currently states:

Non-existent keys are treated as empty strings.

However, BITPOS distinguishes between a missing key and an existing empty string (""):

Non-existent key (o == NULL): Treated as an infinite array of 0 bits.

127.0.0.1:6379> BITPOS nokey 0
(integer) 0
127.0.0.1:6379> BITPOS nokey 1
(integer) -1

Existing empty string (""): Contains 0 allocated bytes/bits.

127.0.0.1:6379> BITPOS empty 0
(integer) -1
127.0.0.1:6379> BITPOS empty 1
(integer) -1

As per discussion in redis/redis#15987 this is the intended behaviour.
This PR updates the final note on the page to accurately describe this difference and prevent confusion.


Note

Low Risk
Documentation-only change to BITPOS; no runtime or API behavior changes.

Overview
Updates the BITPOS command docs to fix misleading behavior for missing vs empty keys.

The old note said non-existent keys are treated like empty strings. The new text explains that a missing key is modeled as an infinite array of 0 bits (BITPOS … 0 → 0, BITPOS … 1 → -1), while an existing key with value "" has no bits (BITPOS for 0 or 1 → -1). This matches intended server behavior (redis/redis#15987).

Reviewed by Cursor Bugbot for commit 21ee67c. Bugbot is set up for automated code reviews on this repo. Configure here.

@CLAassistant

CLAassistant commented Oct 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@dwdougherty dwdougherty left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for this contribution, @itsMathew! Much appreciated. Approved.

@dwdougherty dwdougherty self-assigned this Oct 16, 2026
@dwdougherty dwdougherty added cmds oss Redis Open Source labels Oct 16, 2026
@dwdougherty
dwdougherty merged commit 3d65553 into redis:main Oct 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmds oss Redis Open Source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] BITPOS inconsistency between empty and non-existing keys

3 participants