本文整理汇总了Golang中github.com/mediocregopher/radix/v2/pool.Pool类的典型用法代码示例。如果您正苦于以下问题:Golang Pool类的具体用法?Golang Pool怎么用?Golang Pool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pool类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: migrateRange
func migrateRange(wg *sync.WaitGroup, pool *pool.Pool, start int64, end int64) {
defer wg.Done()
conn, err := pool.Get()
if err != nil {
log.Fatal(err)
}
defer pool.Put(conn)
keys, err := conn.Cmd("LRANGE", "image:all", start, end).List()
if err != nil {
log.Fatal(err)
}
for _, key := range keys {
data, err := conn.Cmd("HGET", "image:file:"+key, "data").Bytes()
if err != nil {
log.Fatal(err)
}
fid := saveFileToFS(data)
conn.Cmd("HDEL", "image:file:"+key, "data")
conn.Cmd("HSET", "image:file:"+key, "dfid", fid)
processSubImages(conn, "cache", key)
processSubImages(conn, "smart", key)
}
}
开发者ID:ququzone,项目名称:image-server,代码行数:26,代码来源:redis2seaweedfs.go
示例2: askRedis
func askRedis(w http.ResponseWriter, words []string, pool *radix.Pool) {
w.Header().Add("Server", "go-search/redis")
const (
_token = "t:"
_content = "c:"
)
tokens := make([]string, len(words))
for i, word := range words {
tokens[i] = _token + word
}
redis, err := pool.Get()
if err != nil {
http.Error(w, fmt.Sprintf("Redis error: %v", err), http.StatusInternalServerError)
// do not return connection into the pool
return
}
rIds := redis.Cmd("SINTER", tokens)
if rIds.Err != nil {
http.Error(w, fmt.Sprintf("Redis error: %v", rIds.Err), http.StatusInternalServerError)
// do not return connection into the pool
return
}
lIds, _ := rIds.List()
for _, id := range lIds {
rContent := redis.Cmd("GET", _content+id)
var title string
if rIds.Err != nil {
title = fmt.Sprintf("(redis error: %v)", rIds.Err)
} else {
title, _ = rContent.Str()
}
fmt.Fprintf(w, "%v,%v\n", id, title)
}
pool.Put(redis)
}
开发者ID:vestel,项目名称:ldn-beam-search,代码行数:35,代码来源:main.go
示例3: NewRedisPipe
/*
* Creates a new Pipe that has access to Redis.
*/
func NewRedisPipe(redisPool pool.Pool) rabbitbeans.Pipe {
client, err := redisPool.Get()
if err != nil {
// handle error
rabbitbeans.FailOnError(err, "Cannot get redis connection from pool")
}
return RedisPipe{client}
}
开发者ID:urjitbhatia,项目名称:rabbitbeans,代码行数:11,代码来源:redisPipe.go
示例4: resetInnerUsingPool
func (c *Cluster) resetInnerUsingPool(p *pool.Pool) error {
// If we move the throttle check to be in here we'll have to fix the test in
// TestReset, since it depends on being able to call Reset right after
// initializing the cluster
client, err := p.Get()
if err != nil {
return err
}
defer p.Put(client)
pools := map[string]*pool.Pool{}
elems, err := client.Cmd("CLUSTER", "SLOTS").Array()
if err != nil {
return err
} else if len(elems) == 0 {
return errors.New("empty CLUSTER SLOTS response")
}
var start, end, port int
var ip, slotAddr string
var slotPool *pool.Pool
var ok, changed bool
for _, slotGroup := range elems {
slotElems, err := slotGroup.Array()
if err != nil {
return err
}
if start, err = slotElems[0].Int(); err != nil {
return err
}
if end, err = slotElems[1].Int(); err != nil {
return err
}
slotAddrElems, err := slotElems[2].Array()
if err != nil {
return err
}
if ip, err = slotAddrElems[0].Str(); err != nil {
return err
}
if port, err = slotAddrElems[1].Int(); err != nil {
return err
}
// cluster slots returns a blank ip for the node we're currently
// connected to. I guess the node doesn't know its own ip? I guess that
// makes sense
if ip == "" {
slotAddr = p.Addr
} else {
slotAddr = ip + ":" + strconv.Itoa(port)
}
for i := start; i <= end; i++ {
c.mapping[i] = slotAddr
}
if slotPool, ok = c.pools[slotAddr]; ok {
pools[slotAddr] = slotPool
} else {
slotPool, err = c.newPool(slotAddr, true)
if err != nil {
return err
}
changed = true
pools[slotAddr] = slotPool
}
}
for addr := range c.pools {
if _, ok := pools[addr]; !ok {
c.pools[addr].Empty()
delete(c.poolThrottles, addr)
changed = true
}
}
c.pools = pools
if changed {
select {
case c.ChangeCh <- struct{}{}:
default:
}
}
return nil
}
开发者ID:75912001,项目名称:radix.v2,代码行数:88,代码来源:cluster.go
注:本文中的github.com/mediocregopher/radix/v2/pool.Pool类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论