Add ExHash type, support field expire #408
Closed
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.
Background
I opened a Discussion #399 in which we discussed support TTL for member and I proposed a draft design. Based on this design, I extended the
Hash
type to support field expiration.Design
ExHash
Hash
Type, we encode expire time in the value of subkey:metadata:
subkey:
Encode expire in subkey's value:
Hash
,ExHash
has the following special commands:Returns OK on success. When the seconds parameter is invalid, the command returns an error.
Returns 1 on success or 0 if key or field does not exist. When the seconds parameter is invalid, the command returns an error.
Returns 1 on success or 0 if key or field does not exist. The command returns an error when the timestamp parameter is invalid.
Note: If timestamp is less than the current timestamp, the field will not set the lifetime.
Returns 0 if field has no expiration set or if ExHash or field does not exist.
Return the number of fields in a ExHash. Returns 0 if key does not exist.
Returns the ExHash's fields and their values as a list, along with the ttl (-1 if no expire is set). If the key does not exist, the empty list is returned.
The other commands are the same as
Hash
. In particular, I didn't implement EXHMSET (synonymous with HMSET) because this command can be used instead of EXHSET (synonymous with HSET) to set multiple fields and values.Implement
RedisType
, calledkRedisExHash
Hash
class and add member variablessupport_field_expire_
to determine whether field expiration is supported. When get the value of the field, we need to check expire.SubKeyFilter::IsKeyExpired
, judge whether the Value expire. Note that we do not update the size in metadata because this accesses theStorage
object and causes data race, which will affect performance. So the size inExHash
metadata is inaccurate, and it contains fields that have expired.