當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Conn.Err方法代碼示例

本文整理匯總了Golang中github.com/garyburd/redigo/redis.Conn.Err方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Err方法的具體用法?Golang Conn.Err怎麽用?Golang Conn.Err使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/garyburd/redigo/redis.Conn的用法示例。


在下文中一共展示了Conn.Err方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: UpdateRedis

func UpdateRedis(readChan chan *Distribution, id int) error {
	var redisConn redis.Conn
	var now int
	lastStatusTime := int(time.Now().Unix())
	updateCount := 0
	for dist := range readChan {
		// Only do a update if we have all the data necissary or we expect
		// there to be a decay event
		now = int(time.Now().Unix())
		if dist.Full() || float64(now-dist.LastSyncT)*dist.Rate > 0.75 {
			redisConn = redisServer.GetConnection()
			err := UpdateDistribution(redisConn, dist)
			if err != nil {
				log.Printf("[%d] Failed to update: %s: %v: %s", id, dist.Name, redisConn.Err(), err.Error())
			}
			updateCount += 1
			if now-lastStatusTime > *UpdateOutputTime {
				rate := float64(updateCount) / float64(now-lastStatusTime)
				log.Printf("[%d] Performing redis updates at %e updates/second", id, rate)
				lastStatusTime = now
				updateCount = 0
			}
			redisConn.Close()
		}
	}
	return nil
}
開發者ID:mynameisfiber,項目名稱:forgettable,代碼行數:27,代碼來源:redis_utils.go

示例2: UpdateRedis

func UpdateRedis(readChan chan *Distribution, id int) error {
	var redisConn redis.Conn
	for dist := range readChan {
		log.Printf("[%d] Updating distribution: %s", id, dist.Name)

		redisConn = redisServer.GetConnection()
		err := UpdateDistribution(redisConn, dist)
		if err != nil {
			log.Printf("[%d] Failed to update: %s: %v: %s", id, dist.Name, redisConn.Err(), err.Error())
		}
		redisConn.Close()
	}
	return nil
}
開發者ID:gitDiscovered,項目名稱:forgettable,代碼行數:14,代碼來源:redis_utils.go

示例3: Do

func (r *RedisStorage) Do(commandName string, args ...interface{}) (interface{}, error) {
	var conn redis.Conn
	i := r.retry
	for ; i > 0; i-- {
		conn = r.pool.Get()
		err := conn.Err()
		if err == nil {
			break
		} else {
			//log.Warnf("failed to get conn from pool (%s)", err)
		}
		time.Sleep(2 * time.Second)
	}
	if i == 0 || conn == nil {
		return nil, fmt.Errorf("failed to find a useful redis conn")
	} else {
		ret, err := conn.Do(commandName, args...)
		conn.Close()
		return ret, err
	}
}
開發者ID:houcy,項目名稱:push,代碼行數:21,代碼來源:redis.go

示例4: put

func (p *connectionPool) put(conn redis.Conn) {
	p.mu.Lock()
	defer p.mu.Unlock()

	if conn == nil || conn.Err() != nil {
		// Failed to dial, closed, or some other problem
		if p.outstanding > 0 {
			p.outstanding--
		}
		p.co.Signal() // someone can try to dial
		return
	}

	if len(p.available) >= p.max {
		go conn.Close() // don't block
		return
	}

	p.available = append(p.available, conn)
	if p.outstanding > 0 {
		p.outstanding--
	}
	p.co.Signal()
}
開發者ID:Greentor,項目名稱:roshi,代碼行數:24,代碼來源:connection_pool.go


注:本文中的github.com/garyburd/redigo/redis.Conn.Err方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。