Code Monkey home page Code Monkey logo

consistenthash's Introduction

consistenthash

English: This repo is based on this article. And you can find the source code of that article here. Since there is no virtual slot implementation descriped at that article, so I read Groupcache's implementation and add the stuff about virtual slot in this repo.

中文: 此repo实现是基于这篇文章的内容(它的代码在这里)以及Groupcache的一致性Hash算法实现的一个合并,并非个人的原创。因为该文章没有虚拟节点的实现,因此在参考Groupcache的实现,把虚拟节点部分加上。算是对该文章内容的一个小小的升级吧。

Example

package main

import (
	"fmt"
	ch "github.com/AbelLai/consistenthash"
)

func main() {
	ring := ch.NewRing(50)
	ring.AddNodes([]string{"127.0.0.1:3000", "127.0.0.1:3001", "127.0.0.1:3002"})

	request1 := "876532rtyhg"
	node1 := ring.GetNode(request1)
	fmt.Printf("Response Node: %s \n", node1.Id)

	request2 := "8rtyhgd9s8dsdyhsjdhsdsdjshdks"
	node2 := ring.GetNode(request2)
	fmt.Printf("Response Node: %s \n", node2.Id)
}

consistenthash's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.