内容:
一 . 客户端Client(普通模式,主从模式,哨兵模式)
二. conn连接(连接, pipline, 发布订阅等)
三. 示例程序(连接, pipline, 发布订阅等)
客户端
-
Client 普通模式的客户端
go redis依据用途提供了多种客户端创建的函数, 如下:
func NewClient(opt *Options) *Client func NewFailoverClient(failoverOpt *FailoverOptions) *Client func (c *Client) Context() context.Context func (c *Client) Do(args ...interface{}) *Cmd func (c *Client) DoContext(ctx context.Context, args ...interface{}) *Cmd func (c *Client) Options() *Options func (c *Client) PSubscribe(channels ...string) *PubSub func (c *Client) Pipeline() Pipeliner func (c *Client) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) func (c *Client) PoolStats() *PoolStats func (c *Client) Process(cmd Cmder) error func (c *Client) ProcessContext(ctx context.Context, cmd Cmder) error func (c *Client) SetLimiter(l Limiter) *Client func (c *Client) Subscribe(channels ...string) *PubSub func (c *Client) TxPipeline() Pipeliner func (c *Client) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) func (c *Client) Watch(fn func(*Tx) error, keys ...string) error func (c *Client) WithContext(ctx context.Context) *Client
NewClient 创建一个普通连接
NewFailoverClient 具有故障检测以及故障转移的client
PSubscribe / Subscribe 发布订阅模式的client
Pipeline 启用pipline管道模式的client
PoolStats 连接池状态
Close 关闭连接
-
集群模式的ClusterClient
func NewClusterClient(opt *ClusterOptions) *ClusterClient func (c *ClusterClient) Close() error func (c *ClusterClient) Context() context.Context func (c *ClusterClient) DBSize() *IntCmd func (c *ClusterClient) Do(args ...interface{}) *Cmd func (c *ClusterClient) DoContext(ctx context.Context, args ...interface{}) *Cmd func (c *ClusterClient) ForEachMaster(fn func(client *Client) error) error func (c *ClusterClient) ForEachNode(fn func(client *Client) error) error func (c *ClusterClient) ForEachSlave(fn func(client *Client) error) error func (c *ClusterClient) Options() *ClusterOptions func (c *ClusterClient) PSubscribe(channels ...string) *PubSub func (c *ClusterClient) Pipeline() Pipeliner func (c *ClusterClient) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) func (c *ClusterClient) PoolStats() *PoolStats func (c *ClusterClient) Process(cmd Cmder) error func (c *ClusterClient) ProcessContext(ctx context.Context, cmd Cmder) error func (c *ClusterClient) ReloadState() error func (c *ClusterClient) Subscribe(channels ...string) *PubSub func (c *ClusterClient) TxPipeline() Pipeliner func (c *ClusterClient) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) func (c *ClusterClient) Watch(fn func(*Tx