Skip to content

fix: distinguish a stored nil from a missing key in fetch/2 - #20

Merged
nmbrone merged 2 commits into
mainfrom
fix/fetch-stored-nil
Sep 2, 2026
Merged

fix: distinguish a stored nil from a missing key in fetch/2#20
nmbrone merged 2 commits into
mainfrom
fix/fetch-stored-nil

Conversation

@nmbrone

@nmbrone nmbrone commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Because fetch/2 was implemented on top of get/3, a key holding nil was reported as :error — indistinguishable from a key that was never set:

Rkv.put(:bucket, :key, nil)
Rkv.fetch(:bucket, :key)
#=> :error   # expected {:ok, nil}

That defeats the only reason fetch/2 exists alongside get/3.

fetch/2 now reads from ETS directly and get/3 is defined in terms of it, so there is a single lookup site. Cost is unchanged: one registry read for the table id, one :ets.lookup/2.

Covered by a test asserting a stored nil and a missing key are told apart.

fetch/2 was implemented on top of get/3, so a key holding nil came back
as :error — indistinguishable from a key that was never set. That
defeats the only reason fetch/2 exists alongside get/3.

Read from ETS directly in fetch/2 and define get/3 in terms of it, so
there is a single lookup site. The cost is unchanged: one registry read
for the table id, one :ets.lookup/2.
@nmbrone
nmbrone merged commit 2f58948 into main Sep 2, 2026
1 check passed
@nmbrone
nmbrone deleted the fix/fetch-stored-nil branch September 2, 2026 07:07
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.

1 participant