redis

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: Apache-2.0, Apache-2.0 Imports: 17 Imported by: 0

README

redis-go-cluster

Forked from github.com/wuxibin89/redis-go-cluster.

Changes:

  1. return common.Nil if redis reply nil error
  2. fixed some bugs
  3. transaction

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSlot

func GetSlot(arg interface{}) (uint16, error)

Types

type Batch

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

Batch pack multiple commands, which should be supported by Do method.

func (*Batch) Exec

func (bat *Batch) Exec() ([]interface{}, error)

func (*Batch) GetBatchSize

func (batch *Batch) GetBatchSize() int

func (*Batch) Len

func (batch *Batch) Len() int

func (*Batch) Put

func (batch *Batch) Put(cmd string, args ...interface{}) error

Put add a redis command to batch, DO NOT put MGET/MSET/MSETNX. it ignores multi/exec transaction

type Cluster

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

Cluster is a redis client that manage connections to redis nodes, cache and update cluster info, and execute all kinds of commands. Multiple goroutines may invoke methods on a cluster simutaneously.

func NewCluster

func NewCluster(options *Options) (*Cluster, error)

NewCluster create a new redis cluster client with specified options.

func (*Cluster) ChooseNodeWithCmd

func (cluster *Cluster) ChooseNodeWithCmd(cmd string, args ...interface{}) (*redisNode, error)

func (*Cluster) Close

func (cluster *Cluster) Close()

Close cluster connection, any subsequent method call will fail.

func (*Cluster) Do

func (cluster *Cluster) Do(cmd string, args ...interface{}) (interface{}, error)

Do excute a redis command with random number arguments. First argument will be used as key to hash to a slot, so it only supports a subset of redis commands. / SUPPORTED: most commands of keys, strings, lists, sets, sorted sets, hashes. NOT SUPPORTED: scripts, transactions, clusters.

Particularly, MSET/MSETNX/MGET are supported using result aggregation. To MSET/MSETNX, there's no atomicity gurantee that given keys are set at once. It's possible that some keys are set, while others not.

See README.md for more details. See full redis command list: http://www.redis.io/commands

func (*Cluster) IterateNodes

func (cluster *Cluster) IterateNodes(result func(string, interface{}, error), cmd string, args ...interface{})

func (*Cluster) NewBatch

func (cluster *Cluster) NewBatch() *Batch

NewBatch create a new batch to pack mutiple commands.

func (*Cluster) NewBatcher

func (cluster *Cluster) NewBatcher() common.CmdBatcher

func (*Cluster) RunBatch

func (cluster *Cluster) RunBatch(bat *Batch) ([]interface{}, error)

RunBatch execute commands in batch simutaneously. If multiple commands are directed to the same node, they will be merged and sent at once using pipeling.

type Options

type Options struct {
	StartNodes []string // Startup nodes

	ConnTimeout  time.Duration // Connection timeout
	ReadTimeout  time.Duration // Read timeout
	WriteTimeout time.Duration // Write timeout

	KeepAlive int           // Maximum keep alive connecion in each node
	AliveTime time.Duration // Keep alive timeout

	Password string

	HandleMoveError bool
	HandleAskError  bool
	// contains filtered or unexported fields
}

Options is used to initialize a new redis cluster.

Jump to

Keyboard shortcuts

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