Skip to content

ring: inline rendezvous hashing and remove external dependency#3762

Merged
ndyakov merged 5 commits into
redis:masterfrom
bigsk05:master
Apr 7, 2026
Merged

ring: inline rendezvous hashing and remove external dependency#3762
ndyakov merged 5 commits into
redis:masterfrom
bigsk05:master

Conversation

@bigsk05

@bigsk05 bigsk05 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Why not keep the dependency?

The original implementation is small (~50 LOC) and stable. Inlining it:

  • avoids pulling an extra dependency into go-redis
  • removes license management overhead
  • keeps behavior fully deterministic and test-covered

Additionally, avoiding a single-purpose dependency helps keep the
dependency graph minimal and easier to maintain.

Changes

  • Inline a minimal rendezvous hashing implementation
  • Remove dependency on github.com/dgryski/go-rendezvous
  • Keep algorithm identical to upstream:
    • same hash combination (khash ^ nodehash)
    • same xorshift* mixing function
    • same iteration/order semantics

Compatibility

No behavior changes are intended.

Notes

The implementation is intentionally minimal and mirrors the original
algorithm to ensure deterministic behavior.

Checklist

  • No public API changes
  • No behavior changes

Note

Medium Risk
Changes the ring sharding hash implementation and removes an external dependency; any subtle mismatch could alter key-to-shard mapping and affect routing in Ring deployments.

Overview
Replaces the Ring consistent-hash implementation with an in-repo rendezvous (HRW) hash (internal/hashtag/RendezvousHash) and updates ring.go to use it instead of github.com/dgryski/go-rendezvous.

Removes the go-rendezvous dependency from the root module plus all example/* and extra/* modules, and adds a new test suite (internal/hashtag/rendezvous_test.go) to validate determinism, distribution, and basic stability characteristics.

Written by Cursor Bugbot for commit 08832cc. This will update automatically on new commits. Configure here.

Replace usage of github.com/dgryski/go-rendezvous with an internal
implementation to eliminate the external dependency and avoid licence
propagation concerns.

The implementation preserves the exact hashing algorithm and behaviour:
- same hash combination: khash ^ nhash
- same mixing function (xorshift* variant)
- same node ordering semantics

No functional changes intended.
@jit-ci

jit-ci Bot commented Apr 1, 2026

Copy link
Copy Markdown

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@jit-ci

jit-ci Bot commented Apr 1, 2026

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@bigsk05 bigsk05 marked this pull request as ready for review April 1, 2026 20:46
Copilot AI review requested due to automatic review settings April 1, 2026 20:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the external github.com/dgryski/go-rendezvous dependency by inlining an equivalent rendezvous (HRW) hashing implementation and wiring Ring’s default consistent-hash implementation to use it.

Changes:

  • Replaced the go-rendezvous wrapper usage in ring.go with an internal rendezvous hash implementation.
  • Added internal/hashtag rendezvous hash implementation + basic unit tests.
  • Removed go-rendezvous from the root module and various nested example/extra modules’ go.mod/go.sum.

Reviewed changes

Copilot reviewed 23 out of 43 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ring.go Switch default Ring consistent hashing implementation to the new internal rendezvous hash.
internal/hashtag/rendezvous.go Adds the inlined rendezvous (HRW) hashing implementation.
internal/hashtag/rendezvous_test.go Adds unit tests for empty/single-node rendezvous behavior.
go.mod Removes direct dependency on github.com/dgryski/go-rendezvous.
go.sum Removes checksums for github.com/dgryski/go-rendezvous.
extra/redisprometheus/go.mod Removes indirect go-rendezvous dependency.
extra/redisprometheus/go.sum Removes go-rendezvous sums.
extra/redisotel/go.mod Removes indirect go-rendezvous dependency.
extra/redisotel/go.sum Removes go-rendezvous sums.
extra/redisotel-native/go.mod Removes indirect go-rendezvous dependency.
extra/redisotel-native/go.sum Removes go-rendezvous sums.
extra/rediscmd/go.mod Removes indirect go-rendezvous dependency.
extra/rediscmd/go.sum Removes go-rendezvous sums.
extra/rediscensus/go.mod Removes indirect go-rendezvous dependency.
extra/rediscensus/go.sum Removes go-rendezvous sums.
example/tls-connection/go.mod Removes indirect go-rendezvous dependency.
example/tls-connection/go.sum Removes go-rendezvous sums.
example/tls-cert-auth/go.mod Removes indirect go-rendezvous dependency.
example/tls-cert-auth/go.sum Removes go-rendezvous sums.
example/scan-struct/go.mod Removes indirect go-rendezvous dependency.
example/scan-struct/go.sum Removes go-rendezvous sums.
example/redis-bloom/go.mod Removes indirect go-rendezvous dependency.
example/redis-bloom/go.sum Removes go-rendezvous sums.
example/otel/go.mod Removes indirect go-rendezvous dependency.
example/otel/go.sum Removes go-rendezvous sums.
example/otel-metrics/go.mod Removes indirect go-rendezvous dependency.
example/otel-metrics/go.sum Removes go-rendezvous sums.
example/maintnotifiations-pubsub/go.mod Removes indirect go-rendezvous dependency.
example/maintnotifiations-pubsub/go.sum Removes go-rendezvous sums.
example/lua-scripting/go.mod Removes indirect go-rendezvous dependency.
example/lua-scripting/go.sum Removes go-rendezvous sums.
example/hset-struct/go.mod Removes indirect go-rendezvous dependency.
example/hset-struct/go.sum Removes go-rendezvous sums.
example/hll/go.mod Removes indirect go-rendezvous dependency.
example/hll/go.sum Removes go-rendezvous sums.
example/disable-maintnotifications/go.mod Removes indirect go-rendezvous dependency.
example/disable-maintnotifications/go.sum Removes go-rendezvous sums.
example/digest-optimistic-locking/go.mod Removes indirect go-rendezvous dependency.
example/digest-optimistic-locking/go.sum Removes go-rendezvous sums.
example/del-keys-without-ttl/go.mod Removes indirect go-rendezvous dependency.
example/del-keys-without-ttl/go.sum Removes go-rendezvous sums.
example/cluster-mget/go.mod Removes indirect go-rendezvous dependency.
example/cluster-mget/go.sum Removes go-rendezvous sums.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/hashtag/rendezvous.go
Comment thread internal/hashtag/rendezvous_test.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 43 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/hashtag/rendezvous_test.go Outdated
Comment thread internal/hashtag/rendezvous_test.go
Comment thread internal/hashtag/rendezvous_test.go
@bigsk05 bigsk05 marked this pull request as draft April 2, 2026 08:13
@bigsk05 bigsk05 marked this pull request as ready for review April 2, 2026 08:45
ndyakov
ndyakov previously approved these changes Apr 2, 2026

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigsk05 I like this approach and am happy to include it. Yes, removing the dependency is great benefit from having this piece in the library code. Thank you!

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, can we test better for (mostly) even distribution of the keys?

Comment thread internal/hashtag/rendezvous_test.go Outdated

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, thank you @bigsk05!

@ndyakov ndyakov merged commit cd984fa into redis:master Apr 7, 2026
33 checks passed
romanpovol pushed a commit to romanpovol/go-redis that referenced this pull request Apr 8, 2026
…redis#3762)

* ring: remove external rendezvous dependency by inlining implementation

Replace usage of github.com/dgryski/go-rendezvous with an internal
implementation to eliminate the external dependency and avoid licence
propagation concerns.

The implementation preserves the exact hashing algorithm and behaviour:
- same hash combination: khash ^ nhash
- same mixing function (xorshift* variant)
- same node ordering semantics

No functional changes intended.

* Refactor TestRendezvous to remove randomString function

Replaced function with inline string generation for test cases.

* test: refactor RendezvousHash tests to use Ginkgo and Gomega

* test: improve RendezvousHash test for per-instance determinism and distribution balance

* test: enhance distribution verification in RendezvousHash tests
ndyakov added a commit that referenced this pull request Apr 9, 2026
* feat(vectorset): WIP

* feat(vectorsets): WITHATTRIBS & VIsMember

* fix(vectorsets): fix tests

* fix(vectorsets): improve doctest/

* feat(vectorsets): add test with nil attrs

* fix(vectorsets): typo Epsilon

* fix: review issues

* chore(go): use -compat=1.24 (#3754)

Signed-off-by: Xiaolong Chen <fukua95@gmail.com>

* chore(maps): Use `maps.Keys`, `slices.Collect` and `slices.Contains` instead of custom functions (#3758)

* Optimize: Use modern Go standard library (maps.Keys, slices.Collect, slices.Contains) instead of custom functions

* format

* chore(deps): bump codecov/codecov-action from 5 to 6 (#3757)

Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5 to 6.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](codecov/codecov-action@v5...v6)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(ring): inline rendezvous hashing and remove external dependency (#3762)

* ring: remove external rendezvous dependency by inlining implementation

Replace usage of github.com/dgryski/go-rendezvous with an internal
implementation to eliminate the external dependency and avoid licence
propagation concerns.

The implementation preserves the exact hashing algorithm and behaviour:
- same hash combination: khash ^ nhash
- same mixing function (xorshift* variant)
- same node ordering semantics

No functional changes intended.

* Refactor TestRendezvous to remove randomString function

Replaced function with inline string generation for test cases.

* test: refactor RendezvousHash tests to use Ginkgo and Gomega

* test: improve RendezvousHash test for per-instance determinism and distribution balance

* test: enhance distribution verification in RendezvousHash tests

---------

Signed-off-by: Xiaolong Chen <fukua95@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: cxljs <fukua95@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bigsk <i@ianxia.com>
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants