Skip to content

Add Valkey 9.0 MemcacheService backed by valkey-glide - #527

Merged
stickfigure merged 1 commit into
objectify:masterfrom
frew:valkey-cache
May 6, 2026
Merged

stickfigure merged 1 commit into
objectify:masterfrom
frew:valkey-cache

Conversation

@frew

@frew frew commented May 3, 2026

Copy link
Copy Markdown
Contributor

Implements ValkeyCacheService using the native SET ... IFEQ comparison-value [EX seconds] command introduced in Valkey 8.1/9.0, so CAS is a single round trip per key instead of a WATCH/MULTI/EXEC dance. Cold-cache reads bootstrap a single-byte 0x00 null sentinel via SET NX (the sentinel cannot collide with Java-serialized data, which always begins 0xAC 0xED).

Adds TestContainers-based extensions and ports BasicCache, Caching, CachingDatastore, CachingUncacheable, and EvilMemcacheBug tests to run against a real valkey/valkey:9.0 container. Includes a new ValkeyCacheServiceTests with direct coverage of the null sentinel, cold-cache bootstrap, CAS win/lose/replace/partial-success, native EX expiration, and a multi-threaded contention test asserting exactly one CAS winner.

Implements ValkeyCacheService using the native SET ... IFEQ comparison-value
[EX seconds] command introduced in Valkey 8.1/9.0, so CAS is a single round
trip per key instead of a WATCH/MULTI/EXEC dance. Cold-cache reads bootstrap
a single-byte 0x00 null sentinel via SET NX (the sentinel cannot collide
with Java-serialized data, which always begins 0xAC 0xED).

Adds TestContainers-based extensions and ports BasicCache, Caching,
CachingDatastore, CachingUncacheable, and EvilMemcacheBug tests to run
against a real valkey/valkey:9.0 container. Includes a new
ValkeyCacheServiceTests with direct coverage of the null sentinel,
cold-cache bootstrap, CAS win/lose/replace/partial-success, native EX
expiration, and a multi-threaded contention test asserting exactly one
CAS winner.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@frew

frew commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

@stickfigure Not sure if you're working any on objectify these days, but Google announced that they're sunsetting Memorystore (Memcache) albeit on a multi-year timeline. The replacement is Valkey, which is AWS rebrand of Redis. Valkey's added direct support for CAS, so figured I'd just add in support for that.

This PR is mostly via Claude. I've reviewed it at a high level and seems reasonable, but wanted to see if you 1) had interest in this upstream or preferred us just to maintain it for the time being and 2) if you had a preference on sequencing for testing/etc (happy to run with it, deploy at Streak and get prod testing, then come back).

@stickfigure
stickfigure merged commit 00c7c5a into objectify:master May 6, 2026
@stickfigure

Copy link
Copy Markdown
Contributor

@frew looks good to me. Merged and interested in the upstream - let me know if you're happy about it, I can merge changes and when you greenlight it roll a release.

frew pushed a commit to frew/objectify that referenced this pull request Jul 8, 2026
Builds on the initial ValkeyCacheService (PR objectify#527) with three changes:

- Cluster-safe: hold the client as a BaseClient (standalone GlideClient
  or GlideClusterClient). Multi-key operations are issued as concurrent
  per-key commands instead of MGET/MSET/DEL, which would fail with
  CROSSSLOT on a cluster. CAS commands are routed to the primary owning
  the key's slot via SlotKeyRoute.

- Bounded keyspace: every write carries a TTL, falling back to a
  configurable defaultExpirationSeconds (default 24h) when the entity
  declares no expiration. A noeviction cluster cannot shed cold entries
  via LRU the way memcache does, so unbounded writes would eventually
  exhaust maxmemory and fail all writers with OOM. Covers plain puts,
  the cold-cache null sentinel, and CAS writes with no explicit TTL.

- Pre-build the default SetOptions once instead of allocating a builder
  on every put/putAll, and add a constructor taking an explicit TTL.

Squashed from the StreakYC/objectify streak-valkey branch, excluding the
fork's release-versioning and Artifact Registry publishing changes.
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