Repository navigation
Conversation
aleksraiden
approved these changes
Nov 11, 2026
jihuayu
approved these changes
Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
closes #3676
Description
After
HDELremoves the last field of a hash,EXISTSreturns 0 butTTL/PTTLstill return -1, while Redis returns -2 (key does not exist).
Redis removes the whole key once the last field is deleted, so a non-existent key
reports
TTL-2:Kvrocks currently reports -1 for the same sequence, which is the bug:
The root cause is that
Hash::Deletedecrements the metadata size to 0 but keepsthe metadata instead of deleting it.
EXISTSandTYPErely onMetadata::Expired(), which already treats a stored-but-empty container asexpired, so they report the key as gone.
Database::TTL, however, decoded themetadata and returned
metadata.TTL()directly, leaking -1 from the leftoverexpire == 0.This change makes
Database::TTLcheckMetadata::Expired()first and return -2,keeping
TTL/PTTLconsistent withEXISTSandTYPE. Since it is applied on theshared read path, it also covers any other container whose metadata is retained
after becoming empty.
The fix is on the read path only — no storage format, encoding, or replication
change, and no new column family.
Side effects
None. The change only aligns the reported TTL for an already-non-existent key.
Test
RedisHashTest.TTLReportsKeyGoneAfterDeletingLastFieldasserting
TTLis -1 while a field is present and -2 after deleting the lastfield.
TestHash("HDEL - hash becomes empty ...")to assert
TTL/PTTLreturn -2 once the last field is deleted.TestExpiresuite to confirm no regression for the other types onthe shared
Database::TTLpath.AI Usage Disclosure