本文整理匯總了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
}
示例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
}
示例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
}
}
示例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()
}