Skip to content

Support RDB_TYPE_HASH_2 (Valkey 9) in DumpRdbValueVisitor#119

Merged
leonchen83 merged 2 commits into
leonchen83:masterfrom
otheng03:valkey9-hash2
May 6, 2026
Merged

Support RDB_TYPE_HASH_2 (Valkey 9) in DumpRdbValueVisitor#119
leonchen83 merged 2 commits into
leonchen83:masterfrom
otheng03:valkey9-hash2

Conversation

@otheng03

@otheng03 otheng03 commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds parsing support for RDB_TYPE_HASH_2 (opcode 22, introduced in Valkey 9 / RDB v80), which encodes a hashtable with field-level expirations. Wire format per entry is [field, value, ttl_ms], distinct from RDB_TYPE_HASH_METADATA (Redis 7.4) which uses [ttl, field, value] with a leading minExpire.

Changes

  • DefaultRdbVisitor#applyHash2 — new override that emits KeyStringValueTTLHash with valueRdbType = RDB_TYPE_HASH_2, mirroring applyHashMetadata.
  • DumpRdbValueVisitor#applyHash2 — two branches:
    • When the target version is < 80, downgrade to RDB_TYPE_HASH and drop per-field TTLs so the dump is restorable on pre-Valkey-9 servers.
    • Otherwise, passthrough using the SkipRdbParser + RawByteListener pattern (no re-encoding).
  • Tests in DumpRdbVisitorTest:
    • testHash2Passthrough — asserts re-parsed dump preserves keys, values, and TTLs.
    • testHash2DowngradeToHash — runs DumpRdbVisitor(replicator, 79) and asserts the dump comes through as RDB_TYPE_HASH with TTLs stripped.
  • src/test/resources/dump-hash2.rdb generated against a local Valkey 9 instance (commands documented in a comment above testHash2Passthrough).

Notes

  • I added applyHash2 to DefaultRdbVisitor for now. Wondering if it's time to split the RDB visitor into Redis and Valkey variants — happy either way, just flagging. Thoughts welcome!
  • For the version < 80 case I went with silent downgrade to RDB_TYPE_HASH (dropping per-field TTLs) to keep things compatible with older targets — same approach applyHashMetadata already takes. An alternative would be to throw so the caller knows TTLs were lost. I leaned toward compatibility but I'm not sure it's the right call. What do you think?
  • Bumped the version to 3.12.0 as a placeholder — let me know if you'd prefer something different.

@otheng03 otheng03 marked this pull request as ready for review May 4, 2026 08:33
@leonchen83

Copy link
Copy Markdown
Owner

This PR is awesome — I’ve gone ahead and merged it.

I have an idea: now that this is in place, we could also support format conversion between Valkey and Redis (Valkey → Redis and Redis → Valkey). For example, converting HashMetadata to Hash_2, or Hash_2 back to HashMetadata. It’s just an initial thought for now — after the merge, I’ll spend some time thinking through how we might approach this.

In that case, migrating from Valkey to a newer version of Redis wouldn’t require dropping TTL information anymore.And the reverse would work as well.

@leonchen83 leonchen83 merged commit 205a49e into leonchen83:master May 6, 2026
11 of 12 checks passed
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