当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.Close方法代码示例

本文整理汇总了Golang中github.com/mediocregopher/radix/v2/redis.Client.Close方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Close方法的具体用法?Golang Client.Close怎么用?Golang Client.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/mediocregopher/radix/v2/redis.Client的用法示例。


在下文中一共展示了Client.Close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewCustom

// NewCustom is like New except you can specify a DialFunc which will be
// used when creating new connections for the pool. The common use-case is to do
// authentication for new connections.
func NewCustom(network, addr string, size int, df DialFunc) (*Pool, error) {
	var client *redis.Client
	var err error
	pool := make([]*redis.Client, 0, size)
	for i := 0; i < size; i++ {
		client, err = df(network, addr)
		if err != nil {
			for _, client = range pool {
				client.Close()
			}
			pool = pool[0:]
			break
		}
		pool = append(pool, client)
	}
	p := Pool{
		Network: network,
		Addr:    addr,
		pool:    make(chan *redis.Client, len(pool)),
		df:      df,
	}
	for i := range pool {
		p.pool <- pool[i]
	}
	return &p, err
}
开发者ID:XUJiahua,项目名称:radix.v2,代码行数:29,代码来源:pool.go

示例2: Put

// Put returns a client back to the pool. If the pool is full the client is
// closed instead. If the client is already closed (due to connection failure or
// what-have-you) it will not be put back in the pool
func (p *Pool) Put(conn *redis.Client) {
	if conn.LastCritical == nil {
		select {
		case p.pool <- conn:
		default:
			conn.Close()
		}
	}
}
开发者ID:XUJiahua,项目名称:radix.v2,代码行数:12,代码来源:pool.go

示例3: Put

// Put putss the connection back in its pool. To be used alongside any of the
// Get* methods once use of the redis.Client is done
func (c *Cluster) Put(conn *redis.Client) {
	c.callCh <- func(c *Cluster) {
		p := c.pools[conn.Addr]
		if p == nil {
			conn.Close()
			return
		}

		p.Put(conn)
	}
}
开发者ID:75912001,项目名称:radix.v2,代码行数:13,代码来源:cluster.go

示例4: Empty

// Empty removes and calls Close() on all the connections currently in the pool.
// Assuming there are no other connections waiting to be Put back this method
// effectively closes and cleans up the pool.
func (p *Pool) Empty() {
	var conn *redis.Client
	for {
		select {
		case conn = <-p.pool:
			conn.Close()
		default:
			return
		}
	}
}
开发者ID:XUJiahua,项目名称:radix.v2,代码行数:14,代码来源:pool.go

示例5: cleanupRedis

func cleanupRedis(client *redis.Client) {
	if client != nil {
		defer client.Close()
	}
}
开发者ID:frosenberg,项目名称:go-cloud-stream,代码行数:5,代码来源:redis_test.go


注:本文中的github.com/mediocregopher/radix/v2/redis.Client.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。