chore: simplify, modernize (Go 1.26), update deps#124
Conversation
- Replace `stderr "errors"` alias with stdlib `errors` + `rrerrors` alias for RR errors - Guard all variadic params with `len(keys)==0` instead of `keys==nil` - Use trimmed key consistently in Has/Delete (validate and operate on same value) - Wrap errors in Set/Clear with `errors.E(op, err)` - Merge MGet validate+iterate loops into single pass; use GetMulti single call - Collapse Delete two-loop validate+delete into one loop - Drop zero-value `Flags:0` field and inaccurate `// unsafe convert` comment - Remove dead `if exist != nil` guards (unreachable after err branch) - Switch all `for i := range` index loops to range-over-value (Go 1.22) - Inline one-use `keyTrimmed` in Get - Fix `if s.Addr==nil` → `len(s.Addr)==0` in InitDefaults - Fix duplicate/misleading ErrCacheMiss comment in Delete
|
Warning Review limit reached
More reviews will be available in 45 minutes and 20 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Simplifies and modernizes the memcached KV driver: aliases the RoadRunner errors package as rrerrors so the stdlib errors can be used directly for errors.Is, switches variadic-empty checks to len(...) == 0, collapses duplicate validate/fetch loops, uses GetMulti in MGet, ensures Has/Delete operate on the trimmed key, and wraps previously bare returns in Set/Clear with the op-tagged error.
Changes:
- Rename
errorsimport torrerrorsand use stdliberrors.Isformemcache.ErrCacheMisschecks. - Tighten/simplify
Has,MGet,Set,Delete,Clear: nil→len checks, single-pass loops,GetMulti, consistentrrerrors.E(op, err)wrapping, range-over-value loops. Config.InitDefaultsnow defaults whenAddris nil or empty (len(s.Addr) == 0).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| memcachedkv/driver.go | Errors-package alias, simplified loops/checks, GetMulti, consistent error wrapping, trimmed-key usage in Has/Delete. |
| memcachedkv/config.go | Default-address check now covers empty slices as well as nil. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #124 +/- ##
=======================================
Coverage 65.00% 65.00%
=======================================
Files 1 1
Lines 20 20
=======================================
Hits 13 13
Misses 4 4
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Applied fixes
R (review/correctness) — 7 applied:
keys==nil→len(keys)==0in Has, MGet, Set, Delete (catches empty-slice callers)time.Parse/client.Seterrors inSetwrapped witherrors.E(op, err)Clearreturn value wrapped witherrors.E(op, err)+ op name addedkeyTrimmedand operate onkeyTrimmed(was validating trimmed but passing untrimmed key to memcache)S (simplify) — 6 applied:
if exist != nilguard removed in Has (unreachable aftererr != nilbranch)Flags: 0zero-value field omitted frommemcache.Itemliteral// unsafe convertcomment removed fromValue:fieldif s.Addr == nil→len(s.Addr) == 0in config.go InitDefaultsM (modernize Go 1.26) — 4 applied:
for i := range keys { keys[i] }→for _, key := range keys(Go 1.22 range-over-value)Getloop with singleGetMulti(keys)call (otelmemcache exposes it cleanly)keyTrimmedvariable inGetstderr "errors"alias: stdliberrorsused directly, RR errors package aliased asrrerrorsNot applied (needs manual review)
plugin.go:50 — p.tracer always set → nil-guard in driver unreachable: the nil-guard in NewMemcachedDriver is a defensive pattern worth keeping; it's not a correctness issue.Verification