cluster

package
v1.2.10 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Overview

Package cluster provides a server side cluster which is transparent to client. You can connect to any node in the cluster to access all data in the cluster

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply

Copy copies the value stored at the source key to the destination key. the origin and the destination must within the same node.

func Del

func Del(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply

Del atomically removes given writeKeys from cluster, writeKeys can be distributed on any node if the given writeKeys are distributed on different node, Del will use try-commit-catch to remove them

func FlushAll

func FlushAll(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply

FlushAll removes all data in cluster

func FlushDB

func FlushDB(cluster *Cluster, c redis.Connection, cmdLine [][]byte) redis.Reply

FlushDB removes all data in current database

func MGet

func MGet(cluster *Cluster, c redis.Connection, cmdLine CmdLine) redis.Reply

MGet atomically get multi key-value from cluster, writeKeys can be distributed on any node

func MSet

func MSet(cluster *Cluster, c redis.Connection, cmdLine CmdLine) redis.Reply

MSet atomically sets multi key-value in cluster, writeKeys can be distributed on any node

func MSetNX

func MSetNX(cluster *Cluster, c redis.Connection, cmdLine CmdLine) redis.Reply

MSetNX sets multi key-value in database, only if none of the given writeKeys exist and all given writeKeys are on the same node

func Publish

func Publish(cluster *Cluster, c redis.Connection, cmdLine [][]byte) redis.Reply

Publish broadcasts msg to all peers in cluster when receive publish command from client

func Rename

func Rename(cluster *Cluster, c redis.Connection, cmdLine [][]byte) redis.Reply

Rename renames a key, the origin and the destination must within the same node

func RenameNx

func RenameNx(cluster *Cluster, c redis.Connection, cmdLine [][]byte) redis.Reply

RenameNx renames a key, only if the new key does not exist. The origin and the destination must within the same node

func Subscribe

func Subscribe(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply

Subscribe puts the given connection into the given channel

func UnSubscribe

func UnSubscribe(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply

UnSubscribe removes the given connection from the given channel

Types

type Cluster

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

Cluster represents a node of godis cluster it holds part of data and coordinates other nodes to finish transactions

func MakeCluster

func MakeCluster() *Cluster

MakeCluster creates and starts a node of cluster

func (*Cluster) AfterClientClose

func (cluster *Cluster) AfterClientClose(c redis.Connection)

AfterClientClose does some clean after client close connection

func (*Cluster) Close

func (cluster *Cluster) Close()

Close stops current node of cluster

func (*Cluster) Exec

func (cluster *Cluster) Exec(c redis.Connection, cmdLine [][]byte) (result redis.Reply)

Exec executes command on cluster

func (*Cluster) Join

func (cluster *Cluster) Join(seed string) protocol.ErrorReply

Join send `gcluster join` to node in cluster to join

func (*Cluster) LoadConfig

func (cluster *Cluster) LoadConfig() protocol.ErrorReply

LoadConfig try to load cluster-config-file and re-join the cluster

func (*Cluster) LoadRDB

func (cluster *Cluster) LoadRDB(dec *core.Decoder) error

type CmdFunc

type CmdFunc func(cluster *Cluster, c redis.Connection, cmdLine CmdLine) redis.Reply

CmdFunc represents the handler of a redis command

type CmdLine

type CmdLine = [][]byte

CmdLine is alias for [][]byte, represents a command line

type Node

type Node struct {
	ID    string
	Addr  string
	Slots []*Slot // ascending order by slot id
	Flags uint32
	// contains filtered or unexported fields
}

Node represents a node and its slots, used in cluster internal messages

type Raft

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

func (*Raft) Close

func (raft *Raft) Close() error

func (*Raft) GetNode

func (raft *Raft) GetNode(nodeID string) *Node

func (*Raft) GetNodes

func (raft *Raft) GetNodes() []*Node

func (*Raft) GetSelfNodeID

func (raft *Raft) GetSelfNodeID() string

GetSelfNodeID returns node id of current node

func (*Raft) GetSlots

func (raft *Raft) GetSlots() []*Slot

func (*Raft) Join

func (raft *Raft) Join(seed string) protocol.ErrorReply

func (*Raft) LoadConfigFile

func (raft *Raft) LoadConfigFile() protocol.ErrorReply

func (*Raft) NewNode

func (raft *Raft) NewNode(addr string) (*Node, error)

NewNode creates a new Node when a node request self node for joining cluster

func (*Raft) SetSlot

func (raft *Raft) SetSlot(slotIDs []uint32, newNodeID string) protocol.ErrorReply

SetSlot propose

func (*Raft) StartAsSeed

func (raft *Raft) StartAsSeed(listenAddr string) protocol.ErrorReply

StartAsSeed starts cluster as seed node

type Slot

type Slot struct {
	// ID is uint between 0 and 16383
	ID uint32
	// NodeID is id of the hosting node
	// If the slot is migrating, NodeID is the id of the node importing this slot (target node)
	NodeID string
	// Flags stores more information of slot
	Flags uint32
}

Slot represents a hash slot, used in cluster internal messages

type Transaction

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

Transaction stores state and data for a try-commit-catch distributed transaction

func NewTransaction

func NewTransaction(cluster *Cluster, c redis.Connection, id string, cmdLine [][]byte) *Transaction

NewTransaction creates a try-commit-catch distributed transaction

Jump to

Keyboard shortcuts

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