Fleet WS-00G: add Legion::Cache.set_nx#15
Merged
Conversation
Adds Legion::Cache.set_nx(key, value, ttl:) — a compare-and-set primitive that returns true if the key was written (race won) and false if the key already existed. - Redis: conn.set(key, serialized, nx: true, ex: ttl) - Memcached: conn.add(key, value, ttl) — native atomic add semantics - Memory: mutex-guarded check-and-set with TTL expiry awareness - Facade (Legion::Cache): routes to the active driver; falls back through local/memory tiers following the same pattern as set Specs cover: win/lose semantics, TTL expiry, concurrency (10 threads), serialization pass-through, and the public interface contract. Also fixes a pre-existing helper_spec JSON key assertion that broke when Legion::JSON.dump switched to pretty-print output.
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
Legion::Cache.set_nx(key, value, ttl:)— an atomic set-if-not-exists primitive required by the fleet pipeline for distributed race coordinationtrueif the key was written (won the race),falseif the key already existedDriver implementations
conn.set(key, serialized, nx: true, ex: ttl)— native Redis NX flagconn.add(key, value, ttl)— Dalli's atomic add semanticsThe facade (
Legion::Cache) routes through memory → local → shared adapter following the same pattern asset_sync.Test plan
cache_interface_spec.rb