Skip to content

feat: add hash field TTL commands (HPERSIST, HTTL, HPTTL, HSETEX) - #436

Open
adamrothman wants to merge 10 commits into
alicebob:masterfrom
adamrothman:hash-field-ttl-commands
Open

feat: add hash field TTL commands (HPERSIST, HTTL, HPTTL, HSETEX)#436
adamrothman wants to merge 10 commits into
alicebob:masterfrom
adamrothman:hash-field-ttl-commands

Conversation

@adamrothman

Copy link
Copy Markdown

I'm working on a project that makes use of TTLs for hash values. I'd like to be able to write tests for this functionality, but miniredis currently lacks support for most of the necessary commands. So I put Claude to work!

This PR doesn't include all of the TTL-related commands, but it's a start. If there's an appetite for the rest, I can see about implementing those too.

Summary

Adds wire commands and direct API methods for hash field TTL operations, building on the existing HEXPIRE implementation:

  • HPERSIST — remove expiration from hash fields
  • HTTL — get remaining TTL of hash fields in seconds
  • HPTTL — get remaining TTL of hash fields in milliseconds
  • HSETEX — set hash fields with optional expiration (supports EX, PX, EXAT, PXAT, KEEPTTL, FNX, FXX)
  • Direct API methodsHExpire, HPersist, HTTL, HSetEX on both *Miniredis and *RedisDB
  • Extracted shared parseFieldsArgs helper for the FIELDS numfields field... argument block

Test plan

  • Unit tests for each new wire command (HPERSIST, HTTL, HPTTL, HSETEX)
  • Unit tests for direct API methods (TestDirectHashFieldTTL)
  • Integration tests for all new commands
  • Regression tests — all existing hash tests continue to pass
  • Full test suite passes (go test ./... -count=1)
  • go vet ./... clean

adamrothman and others added 10 commits March 18, 2026 14:45
HSETEX, HPERSIST, HTTL, HPTTL wire commands and direct API methods
(HExpire, HPersist, HTTL, HSetEX).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix method count, add key-does-not-exist behavior, HSETEX no-expiration
semantics, EXAT/PXAT parse-vs-resolve detail, TTL validation rules.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7 tasks covering HPERSIST, HTTL, HPTTL, HSETEX wire commands,
direct API methods, integration tests, and README update.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alicebob

Copy link
Copy Markdown
Owner

Thanks for the PR! It looks good, but I'll have to go through it in detail, which will take a bit.

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.

2 participants