cluster

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cluster implements Redis Cluster style key routing with a static slot map: the keyspace is split into 16384 hash slots, each node serves a set of slot ranges, and a node answers MOVED for keys it doesn't own so cluster-aware clients learn where to send them.

There is no gossip, failover or resharding: the slot map comes from the configuration (cluster-node lines) and is the same on every node.

Index

Constants

View Source
const NumSlots = 16384

NumSlots is the number of hash slots, as in Redis Cluster.

Variables

This section is empty.

Functions

func CRC16

func CRC16(s string) uint16

CRC16 computes CRC16-XMODEM, the checksum Redis Cluster uses for slots.

func HashTag

func HashTag(key string) string

HashTag returns the part of key used for hashing: the text between the first '{' and the next '}' if that is not empty, otherwise the whole key. "{user1}.a" and "{user1}.b" therefore land in the same slot.

func Slot

func Slot(key string) int

Slot returns the hash slot of key.

Types

type Node

type Node struct {
	ID     string
	Host   string
	Port   int
	Ranges [][2]int // inclusive slot ranges, sorted
}

Node is one cluster member from the configuration.

func ParseNode

func ParseNode(line string) (*Node, error)

ParseNode parses "id host:port 0-8191[,10000-10100] [12000]". Ranges may be separated by commas or spaces; a single number is one slot.

func (*Node) Addr

func (n *Node) Addr() string

Addr is "host:port".

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router implements command.ClusterRouter with a static slot map.

func New

func New(enabled bool, selfID string, nodeLines []string, db *store.DB) (*Router, error)

New builds a router. With enabled false it only answers CLUSTER KEYSLOT style questions; Check never redirects.

func Setup

func Setup(e *command.Engine) (*Router, error)

Setup creates the router from the config and sets e.Cluster.

func (*Router) Check

func (r *Router) Check(keys []string) error

Check returns an error if keys don't all hash to one slot (CROSSSLOT), or that slot is served by another node (MOVED) or nobody (CLUSTERDOWN).

func (*Router) Command

func (r *Router) Command(args []string) resp.Value

Command runs a CLUSTER subcommand (args excludes "CLUSTER"). The CLUSTER command is registered with FlagAllKeys, so the caller holds every shard lock (needed by COUNTKEYSINSLOT and GETKEYSINSLOT).

func (*Router) Enabled

func (r *Router) Enabled() bool

Enabled reports whether cluster mode is on.

func (*Router) Info

func (r *Router) Info() [][2]string

Info returns the cluster section of INFO.

func (*Router) Self

func (r *Router) Self() *Node

Self returns this node (nil when disabled).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL