Repository navigation
Clear a key's expiry when set() is called without a TTL - #7
Merged
Merged
Conversation
A null TTL now means the key never expires: set() replaces the value and the expiry together, as Redis SET and PSR-16 set() do. Before, set() without a TTL kept whatever expiry the key had, so a value set on a key whose expiry had passed was gone at once, and a value set on a key with a live expiry inherited it. Array access goes through set() and behaves the same. Removing an expiry counts as a change, so setting a key to the value it already has without a TTL makes hasChanged() true when the key had an expiry. This changes behaviour for callers that relied on set() without a TTL keeping an expiry: they now have to pass the TTL again. Closes #4
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.
Summary
A
nullTTL now means the key never expires.set()replaces the value and the expiry together, as RedisSETand PSR-16set()do. Array access goes throughset(), so it behaves the same.set(key, value, ttl) reject reserved key / ttl <= 0 store value (changed if new or different) if ttl given expiry = now + ttl (changed if it moved) + else if key has an expiry + remove expiry (changed)Before this change, a value set on a key whose expiry had passed was gone at once. A value set on a key with a live expiry kept that expiry, even though the call didn't ask for one.
The
$ttldocblock and the README's Expiring entries and Tracking changes sections describe the new rule.Closes #4
Evidence
Before (
master, using the repro from set() without a TTL keeps the key's old expiry #4):After (this branch, same script):
Tests: 7 new data-provider cases fail against
master'ssrc/and pass on this branch:it_clears_the_expiry_when_setting_without_a_ttl:set()on a key whose expiry has passed, on a key with a live expiry, and on a key that only had an expiry restored from stored data; plusoffsetSet()on a passed and on a live expiry. Each checks the value is still there long after the old expiry.it_changes_when_setting_the_same_value_without_a_ttl_clears_an_expiry: one case with a live expiry, one with an expiry that has passed.The old
it_does_not_change_when_setting_the_same_value_without_a_ttltest now covers only keys with no expiry. PHPStan, ECS, PHPUnit (74 tests) and Infection (MSI 96%, no escaped mutants inMetadata) all pass.Merge Danger
Door: two-way
Reverting the commit restores the old behaviour. Data stored in the meantime keeps working, because the serialized shape is unchanged: a key without an entry in
__expireswas already a valid state.Blast Radius: consumers
The method signatures don't change, so the Roave BC check passes. Behaviour does change, though, and that check can't see it:
set($key, $value)keeping a key's expiry now get a key that never expires. They need to pass the TTL again.hasChanged()returns true) if the key had an expiry. A store that saves onhasChanged()will write that row once.This should be noted in the 1.2.0 release notes, next to change tracking (#5). setono/client-bundle's
src/never sets a key without a TTL to keep its expiry.