Skip to content

refactor: keyspace helpers for expiry, collection cleanup, and error strings - #99

Merged
kacy merged 4 commits into
mainfrom
refactor/keyspace-helpers
Feb 12, 2026
Merged

refactor: keyspace helpers for expiry, collection cleanup, and error strings#99
kacy merged 4 commits into
mainfrom
refactor/keyspace-helpers

Conversation

@kacy

@kacy kacy commented Feb 12, 2026

Copy link
Copy Markdown
Owner

summary

  • added decrement_expiry_if_set and adjust_expiry_count helpers to replace 10+ inline expiry bookkeeping patterns across keyspace methods
  • added cleanup_after_remove to consolidate the "if-empty-remove-key-else-adjust-memory" pattern shared by list_pop, zrem, hdel, and srem
  • consolidated remaining_secs/remaining_ms in time.rs into a shared remaining() helper
  • added WRONGTYPE_MSG and OOM_MSG constants to prevent error string drift across WrongType, IncrError, and IncrFloatError

what was tested

  • cargo clippy -p emberkv-core -- -D warnings — clean
  • cargo test -p emberkv-core — all 301 tests pass
  • all changes are private helpers or constants — no public API changes

kacy added 4 commits February 12, 2026 10:37
extracted two private helpers for the mechanical expiry bookkeeping
that was duplicated across 10+ methods:

- decrement_expiry_if_set: replaces the if-nonzero-saturating-sub
  pattern in try_evict, del, unlink, rename, remove_if_expired
- adjust_expiry_count: replaces the match-on-had/has-expiry pattern
  in set and restore
the "if empty, remove key + adjust memory/expiry; else adjust memory"
pattern appeared identically in list_pop, zrem, hdel, and srem.
extracted cleanup_after_remove() — each call site drops from 8-10
lines to a single call.
these two functions were identical except for a / 1000 divisor.
extracted a shared remaining() helper that both delegate to.
the WRONGTYPE and OOM error strings were duplicated across WrongType,
IncrError, and IncrFloatError Display impls. added WRONGTYPE_MSG and
OOM_MSG constants so they can't drift if one is updated.
@kacy
kacy merged commit 2424344 into main Feb 12, 2026
7 checks passed
@kacy
kacy deleted the refactor/keyspace-helpers branch February 12, 2026 15:52
kacy added a commit that referenced this pull request Feb 19, 2026
…strings (#99)

* refactor: add expiry count helpers to keyspace

extracted two private helpers for the mechanical expiry bookkeeping
that was duplicated across 10+ methods:

- decrement_expiry_if_set: replaces the if-nonzero-saturating-sub
  pattern in try_evict, del, unlink, rename, remove_if_expired
- adjust_expiry_count: replaces the match-on-had/has-expiry pattern
  in set and restore

* refactor: extract cleanup_after_remove helper

the "if empty, remove key + adjust memory/expiry; else adjust memory"
pattern appeared identically in list_pop, zrem, hdel, and srem.
extracted cleanup_after_remove() — each call site drops from 8-10
lines to a single call.

* refactor: consolidate remaining_secs/remaining_ms in time.rs

these two functions were identical except for a / 1000 divisor.
extracted a shared remaining() helper that both delegate to.

* refactor: shared error message constants for WRONGTYPE and OOM

the WRONGTYPE and OOM error strings were duplicated across WrongType,
IncrError, and IncrFloatError Display impls. added WRONGTYPE_MSG and
OOM_MSG constants so they can't drift if one is updated.
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