Skip to content

feat: RANDOMKEY, TOUCH, SORT commands#254

Merged
kacy merged 1 commit intomainfrom
feat/randomkey-touch-sort-v2
Feb 24, 2026
Merged

feat: RANDOMKEY, TOUCH, SORT commands#254
kacy merged 1 commit intomainfrom
feat/randomkey-touch-sort-v2

Conversation

@kacy
Copy link
Copy Markdown
Owner

@kacy kacy commented Feb 24, 2026

summary

adds three convenience commands from the audit backlog (#20) that client libraries and Redis-compatible tools occasionally probe for. none touch the hot path — zero impact on GET/SET throughput.

  • RANDOMKEY: returns a random key from the database, or nil if empty. broadcasts across all shards via engine.broadcast() and picks a random result using reservoir sampling.
  • TOUCH key [key ...]: updates last access time for given keys, returns count that existed. reuses the same multi_key_bool + route_multi fan-out pattern as DEL/EXISTS.
  • SORT key [ASC|DESC] [ALPHA] [LIMIT offset count] [STORE dest]: sorts elements from a list, set, or sorted set. numeric sort by default, lexicographic with ALPHA. STORE variant does two-phase sort + rpush to destination key. BY/GET patterns intentionally deferred — rarely used and adds significant complexity.

~80 LOC new logic, ~40 LOC modified across 6 files (plus tests and CLI metadata).

what was tested

  • cargo fmt --all --check — clean
  • cargo clippy --workspace -- -D warnings — clean
  • cargo test -p ember-protocol — 406 passed
  • cargo test -p emberkv-core — 401 passed
  • cargo test -p ember-server — 134 passed
  • cargo test -p ember-integration-tests — 79 passed
  • new parser tests: RANDOMKEY (2), TOUCH (3), SORT (7 — basic, desc+alpha, limit, store, no-args, is_write with/without store)
  • new keyspace tests: random_key empty/non-empty, touch exists/missing, sort list numeric/alpha-desc/limit, sort set alpha, sort missing key, sort wrong type

design considerations

  • SORT without STORE routes through route! macro for batch dispatch efficiency; SORT with STORE falls through to execute() for two-phase inline handling (sort on source shard → del+rpush on dest shard)
  • TOUCH is categorized as READ | KEYSPACE | FAST (matching Redis), not as a write — it only updates LRU metadata, not user-visible state
  • concurrent mode returns an error for SORT (only supports strings) and uses exists() for TOUCH (no last_access tracking in DashMap entries)
  • cluster slot checks: TOUCH added to multi-key crossslot group; SORT without STORE added to single-key slot check; SORT with STORE gets crossslot validation between source and destination keys

add three convenience commands that client libraries and Redis-compatible
tools occasionally probe for. none of these touch the hot path.

- RANDOMKEY: returns a random key from the database, or nil if empty.
  broadcasts across all shards and picks a random result.
- TOUCH key [key ...]: updates last access time for given keys, returns
  count of keys that existed. uses the same multi_key_bool fan-out
  pattern as DEL/EXISTS.
- SORT key [ASC|DESC] [ALPHA] [LIMIT offset count] [STORE dest]: sorts
  a list, set, or sorted set. STORE variant does two-phase sort+rpush.
  BY/GET patterns intentionally deferred (rarely used, adds complexity).
@kacy kacy merged commit 6a66aa9 into main Feb 24, 2026
5 of 7 checks passed
@kacy kacy deleted the feat/randomkey-touch-sort-v2 branch February 24, 2026 02:15
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