Skip to content

feat: HRANDFIELD and ZRANDMEMBER - #319

Merged
kacy merged 1 commit into
mainfrom
feat/hrandfield-zrandmember
Feb 26, 2026
Merged

feat: HRANDFIELD and ZRANDMEMBER#319
kacy merged 1 commit into
mainfrom
feat/hrandfield-zrandmember

Conversation

@kacy

@kacy kacy commented Feb 26, 2026

Copy link
Copy Markdown
Owner

summary

  • HRANDFIELD: returns random field(s) from a hash; positive count = distinct, negative = allow duplicates; WITHVALUES returns interleaved field-value pairs
  • ZRANDMEMBER: same semantics for sorted sets; WITHSCORES returns interleaved member-score pairs
  • both commands follow the same positive/negative count convention as SRANDMEMBER

tested

  • 7 unit tests in keyspace/hash.rs covering all count modes, WITHVALUES, missing key, wrong type
  • 7 unit tests in keyspace/zset.rs covering all count modes, WITHSCORES, missing key, wrong type
  • 9 integration tests: single return, positive/negative count, WITHVALUES/WITHSCORES, missing key (both commands)
  • cargo clippy -D warnings clean

design notes

  • no AOF record needed — both are pure read commands
  • count=None returns a single bulk string (not a one-element array), matching redis spec
  • count=0 returns an empty array, consistent with SRANDMEMBER behavior

- HRANDFIELD: returns random field(s) from a hash; positive count =
  distinct, negative = allow duplicates; WITHVALUES returns interleaved
  field-value pairs; no count returns a single bulk string
- ZRANDMEMBER: same semantics for sorted sets; WITHSCORES returns
  interleaved member-score pairs
- both follow the same positive/negative count convention as SRANDMEMBER
- 14 unit tests in keyspace/hash.rs and keyspace/zset.rs
- 9 integration tests covering all modes and missing-key edge cases
@kacy
kacy merged commit 0c81224 into main Feb 26, 2026
5 of 7 checks passed
@kacy
kacy deleted the feat/hrandfield-zrandmember branch February 26, 2026 23:44
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