Repository navigation
Releases
Releases · dcbickfo/redcache
v0.4.2
Added
RedisErrorcan now receiveop="read_fallback", whichMetrics
implementations and dashboards that enumerate operations or alert on all
redis.errorsneed to account for.
It counts an attempted uncached retry after a clustered cached read
aborted. It emits one event per uncached retry attempt, whether for one key
or a batch. A pollingGetorGetMultican make more than one attempt.
The count includes retries that fail, return Redis nil, or are canceled
before sending. MissingPTTLpermission can trigger an abort. A
sustained rate alone cannot identify a server-sideEXECabort because
rueidis also reportsErrDoCacheAbortedwhen a connection closes.
Fixed
- Fixed cache misses that could wait for a lock nobody held after a read
without client-side tracking. - Cache reads can refill a missing key after a loader or write callback panics.
- Cached reads follow ASK during Valkey 9 cluster slot migration.
v0.4.1
Fixed
- A
GetorGetMultiloader slower thanLockTTLno longer loops
forever. The Redis lock was never extended while the loader ran, so the
lock expired, the final CAS-set failed withErrLockLost, and the call
retried, re-running the loader indefinitely. The lock is now extended every
LockTTL/3for as long as the loader runs, and a call that loses its lock
more than three times returnsErrLockLostinstead of retrying again. SetandSetMultiroll back when the callback panics. A callback
that panicked, with the panic recovered by the caller, left the write lock in
place forLockTTLand the prior value gone. The prior values are now
restored before the panic continues.- A rollback no longer persists a value that was about to expire. When the
prior value had under a millisecond of TTL left (PTTL0), the restore wrote
it back with no expiry. It now deletes the key. Values with no expiry
(PTTL-1) are still restored without one.
Documentation
- README: write-through
Setsection covering the restore-on-error
precondition and how to handleErrLockLost.
v0.4.0
Breaking
- Go 1.27 is now required. The module, local toolchain pin, and CI all
target Go 1.27. Cache[K, V]is replaced by the non-genericCache. Both type
parameters move to the operations as Go 1.27 generic methods —Get[K, V],
GetMulti[K, V],Peek[K, V],Set[K, V],SetMulti[K, V],
ForceSet[K, V],ForceSetMulti[K, V],Del[K],DelMulti[K],
Touch[K],TouchMulti[K]— so one cache serves every key and value type.
Keys and loaders normally infer both;Peekneeds explicitPeek[K, V]
(nothing to inferVfrom), and an untyped nil passed to a multi-key method
needs explicit type arguments.- Constructors are
New(conn, valCodec),NewKeyed(conn, keyCodec, valCodec), andNewBytes(conn).New[K]andNewStringare gone. Codec[V]andKeyCodec[K]are replaced byany-basedCodecand
KeyCodec. A codec decodes into the operation's*V, following the
encoding/jsondestination pattern; mismatches are returned as errors.
StringKeyCodec(theNewdefault) acceptsstring, any~stringtype,
andencoding.TextMarshaler;KeyCodecFunc[K]accepts exactlyK.
String-underlying key types now take the zero-copy multi-key fast path that
was previously limited toK == string.- No interface form;
redcachetestis removed. Generic methods cannot
satisfy Go interfaces, soCacheis the only type and code under test takes
*Cache.OpenMemory(opts ...MemoryOption)replaces the fake: it returns a
Connbacked by an in-process map, so tests build a realCachewith real
codecs over it.WithMemoryClockreplacesredcachetest.Clock.
Added
JSONV2Codec— opt-inencoding/json/v2codec (nil slices/maps as[]/{},
case-sensitive field matching, duplicate object names rejected).JSONCodec
keepsencoding/jsonv1 semantics and wire format.- The test binary's
TestMainfails the run on any leaked package goroutine,
using Go 1.27'sgoroutineleakprofile;TestConn_Close_LeaksNoGoroutines
pins the same check toConn.Close.
Fixed
- A
Get/GetMultileader that exits on error (cancelled context, Redis
error) releases its local wait entry. Later callers in the same process used
to park on it untilLockTTL, since nothing was written to invalidate it. Set/SetMultithat fail before writing to Redis (cancelled context, read
error) release the local wait entries they created. AGet/GetMultion
the same key used to park on such an entry untilLockTTL.- rueidis's nil invalidation (connection lost,
FLUSHALL/FLUSHDB) now wakes
every local waiter. It was ignored, so after a Redis restart or flush the next
miss on a recently-read key could stall untilLockTTL. - A ttl under 1ms returns
ErrInvalidTTLup front instead of running the
loader and then failing on RedisPX 0. ForceSetMultiwith two keys that encode to the same Redis key returns a
plain error and writes nothing, matchingSetMulti/GetMulti. It used to
return a*BatchKeyErrorlisting only the colliding keys, which implied the
rest had been written.*BatchKeyErrorimplementsUnwrap() []error, soerrors.Is(err, context.Canceled)anderrors.Is(err, ErrLockLost)work on multi-key
writes as they do on single-key ones.OpenMemorynow matches the Redis engine: it drops loader results for keys
that were not requested, dedupes input keys, and copies stored values
instead of aliasing the caller's buffer.GetMultiretry loop no longer races a still-running lock waiter: the
internalWaitForAllgoroutine is joined before the poll fallback returns,
so the reused channel slice is not rewritten underneath it (found by the race
detector; pre-existing).
Changed
github.com/google/uuidis replaced by the Go 1.27 standard-libraryuuid
package; the module has one fewer direct dependency.- Concurrent worker launches use
sync.WaitGroup.Go, typed error matching uses
errors.AsType, and tests uset.Context(),b.Loop(), and stdlib
slicessorting.internal/syncxtiming tests run intesting/synctest
bubbles instead of racing wall-clock deadlines. - golangci-lint is updated to v2.15.0, retaining the full lint and formatting
gates with Go 1.27 generic-method support. The config enables revive's new
use-slices-concat,marshal-receiver, andmultiline-if-initrules, sets
exclusions.warn-unused, and drops exclusion rules that no longer matched
anything (vendor paths, a stale gosec G115 rule, and theredefines-builtin-id
waiver, whose one hit was renamed). - Multi-key paths (
GetMulti,SetMulti,TouchMulti, lock acquire,
CAS-set and unlock) send each phase as one pipeline instead of one pipeline
and goroutine per cluster slot. Every script touches a single key, and
rueidis's cluster client already splits a pipeline per node, runs the nodes
in parallel and follows redirects, so a batch now costs one round trip per
node rather than per slot.internal/cmdxis deleted.
v0.3.1
A patch release for the v0.3 line, backported from the v0.4 work. The rueidis
version is unchanged.
Changed
- The Go floor is now 1.26.10 (
go 1.26.10ingo.mod), up from 1.25. Go
1.25 is out of support and has unfixed standard-library vulnerabilities in
crypto/tlsandcrypto/x509(GO-2026-6607, GO-2026-6809); 1.26.10 is the
first release with both fixes. CI tests on Go 1.26 and 1.27. go fixmodernizers for Go 1.26 are applied (wg.Go,rangeover ints,
min/max), with no behavior change.- CI now runs the suite against a Redis Cluster, covering slot migration
(MOVED and ASK), primary failover, and per-nodeSCRIPT LOADcounts.
Added
ErrMissingValue, returned (wrapped, naming the keys) when aGetMultior
SetMultiloader returns no value for a key it was given.
Fixed
- Multi-key operations no longer recycle the command slice passed to rueidis
DoMulti. On context cancellation rueidis's writer goroutine could still be
reading it, and the pooled reset crashed the process with a nil-pointer
panic. Standalone and sentinel clients were affected, because they hand the
caller's slice to the connection; the cluster client copies commands into
per-node slices first, so cluster deployments were not. GetMultino longer livelocks when its loader omits a key. It used to
re-lock the key and re-run the loader until the context ended; it now fails
fast withErrMissingValue.SetMultireports omitted keys as failed with
ErrMissingValue(restoring their prior value) instead of returning nil.
redcachetest.Fakefollows the same contract.- Multi-key Lua calls (
GetMultimisses,SetMulti,TouchMulti,
multi-key refresh) no longer sendSCRIPT LOADto every node, replicas
included, and wait for it before every batch. They pipelineEVALSHAand
re-send onlyNOSCRIPTreplies asEVAL, saving about one round trip per
call (the slowest node's, on a cluster).
v0.3.0
Highlights
- Introduces the generics-first
Cache[K, V]API, derived from a sharedConn
withNew,NewString, orNewBytes. - Adds typed codecs,
redcachetest.Fake[K, V], theredcacheotelmetrics
adapter, and standalone examples underexamples/. - Hardens refresh and write paths with lock-wait polling fallback, refresh
timeout control, TTL validation, and typed key collision checks. - Raises the minimum Go version to 1.25 and adds CI/security automation.
Breaking Changes
- Replace
NewRedCacheAside/NewPrimeableCacheAsideandCacheAsideOption
withOpenplus functional options, then derive cache views from theConn. - Cache views are operations-only;
Close()and rawClient()access now live
onConn. - Multi-key mutation methods now take
[]K,Metricsimplementers need the new
loader/Redis hooks, andBytesCodecis nowUnsafeBytesCodec.
The on-disk value format is unchanged from v0.2.x. See the README migration
section for concrete v0.2.x -> v0.3.x examples.
v0.2.0
What's Changed
- Add XFetch probabilistic refresh (
RefreshBeta),Touch/TouchMultiAPI,LockWaitDurationmetric, perf refactors by @dcbickfo - Skip duplicate
SET NXunder in-process contention via leader/follower coordination by @dcbickfo - Cut allocs in
Get/GetMultihot path by @dcbickfo - Switch high-volume metrics to count-based and gate noop dispatch by @dcbickfo
- Validate
LockPrefixagainst envelope prefix at construction by @dcbickfo
⚠️ Breaking changes
- On-disk value format changed. Values are now wrapped in
__redcache:v1:<delta_ns>:<payload>so refresh-ahead can read original compute time for XFetch sampling. Reads transparently unwrap; legacy un-wrapped values still serve (withdelta=0). Rolling back from v0.2.0+ to v0.1.7 or earlier requires flushing affected keys — older clients will return the raw envelope as the user value. LockPrefixis now validated at construction. Setting it such that the envelope prefix would look like a lock value returns an error fromNewRedCacheAside(default__redcache:lock:is unaffected).
Full Changelog: v0.1.7...v0.2.0
v0.1.7
v0.1.6
v0.1.5
Fix Indefinite Wait (#4) * adding retry for contested locks and an operation timeout * remove operation timeout * use context to ensure cancellation * Update cacheaside.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>