Skip to content

feat: add FieldValueIter support for Hsetex command #890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

kotahorii
Copy link
Contributor

Summary

This PR adds FieldValueIter method support to the Hsetex command, providing API consistency with other hash commands like Hset and Hmset.

Changes

  • Added HsetexFieldValue.FieldValueIter method in internal/cmds/iter.go

    • Follows the same pattern as existing HsetFieldValue.FieldValueIter implementation
    • Accepts iter.Seq2[string, string] for Go 1.23 iterator support
    • Maintains zero-allocation design philosophy
  • Added comprehensive test coverage in internal/cmds/iter_test.go

    • Added Hsetex test case to the existing iterator test suite
    • Verified compatibility with maps.All() function

API Usage Example

// Before: Only one-by-one field addition
client.B().Hsetex().Key("key").Ex(60).Fields().Numfields(2).
    FieldValue().FieldValue("name", "John").FieldValue("email", "[email protected]").
    Build()

// After: Bulk field addition from map or any iter.Seq2[string, string]
data := map[string]string{"name": "John", "email": "[email protected]"}
client.B().Hsetex().Key("key").Ex(60).Fields().Numfields(2).
    FieldValue().FieldValueIter(maps.All(data)).
    Build()

Testing

  • ✅ All existing tests pass
  • ✅ New iterator test added and passes
  • ✅ Hash command tests continue to pass
  • ✅ Manual verification with sample data confirms correct command generation

Backward Compatibility

This change is fully backward compatible - no existing APIs are modified, only a new method is added.

Fixes #888

🤖 Generated with Claude Code

Add FieldValueIter method to HsetexFieldValue type to provide consistent
API with other hash commands like Hset and Hmset. This allows users to
easily convert struct fields to field-value pairs using Go 1.23 iterators.

Changes:
- Add HsetexFieldValue.FieldValueIter method in iter.go following the same
  pattern as HsetFieldValue.FieldValueIter
- Add comprehensive test coverage in iter_test.go
- Maintains API consistency across hash commands
- Supports zero-allocation design pattern used throughout rueidis

Fixes redis#888

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@rueian
Copy link
Collaborator

rueian commented Aug 3, 2025

Hi @kotahorii, thanks for your PR.
Your commit has been merged into #889.

@rueian rueian closed this Aug 3, 2025
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.

Support FieldValueIter for Hsetex
2 participants