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


Golang Pool.Get方法代码示例

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


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

示例1: NewTransaction

func NewTransaction(pool *redis.Pool) *Transaction {
	t := &Transaction{
		conn:    pool.Get(),
		Actions: make([]*Action, 0),
	}
	return t
}
开发者ID:LindenY,项目名称:gomdise,代码行数:7,代码来源:transaction.go

示例2: Expired

// Expired implements the `func Expired` defined on the Strategy interface. It
// scans iteratively over the Heart's `location` field to look for items that
// have expired. An item is marked as expired iff the last update time happened
// before the instant of the maxAge subtracted from the current time.
func (s HashExpireyStrategy) Expired(location string,
	pool *redis.Pool) (expired []string, err error) {

	now := time.Now()

	cnx := pool.Get()
	defer cnx.Close()

	reply, err := redis.StringMap(cnx.Do("HGETALL", location))
	if err != nil {
		return
	}

	for id, tick := range reply {
		lastUpdate, err := time.Parse(DefaultTimeFormat, tick)

		if err != nil {
			continue
		} else if lastUpdate.Add(s.MaxAge).Before(now) {
			expired = append(expired, id)
		}
	}

	return
}
开发者ID:wulffeld,项目名称:redutil,代码行数:29,代码来源:hash_expiry_strategy.go

示例3: getProcedure

func getProcedure(pool *redis.Pool, endpoint URI) *registrationInfo {
	conn := pool.Get()
	defer conn.Close()

	proceduresKey := fmt.Sprintf("procedures:%s", endpoint)
	procedures, err := redis.Strings(conn.Do("ZREVRANGE", proceduresKey, 0, 1))
	if err != nil {
		out.Debug("Redis error on key %s: %v", proceduresKey, err)
		return nil
	}

	if len(procedures) == 0 {
		return nil
	}

	info := registrationInfo{}

	reply, err := redis.Values(conn.Do("HGETALL", procedures[0]))
	if err != nil {
		out.Debug("Redis error on key %s: %v", procedures[0], err)
		return nil
	}

	err = redis.ScanStruct(reply, &info)
	if err != nil {
		out.Debug("Redis error on key %s: %v", procedures[0], err)
		return nil
	}

	return &info
}
开发者ID:exis-io,项目名称:node,代码行数:31,代码来源:dealer.go

示例4: Build

// Fetch Txos and Txins
func (tx *Tx) Build(rpool *redis.Pool) (err error) {
	c := rpool.Get()
	defer c.Close()
	tx.TxIns = []*TxIn{}
	tx.TxOuts = []*TxOut{}
	txinskeys := []interface{}{}
	for i := range iter.N(int(tx.TxInCnt)) {
		txinskeys = append(txinskeys, fmt.Sprintf("txi:%v:%v", tx.Hash, i))
	}
	txinsjson, _ := redis.Strings(c.Do("MGET", txinskeys...))
	for _, txinjson := range txinsjson {
		ctxi := new(TxIn)
		err = json.Unmarshal([]byte(txinjson), ctxi)
		tx.TxIns = append(tx.TxIns, ctxi)
	}
	txoutskeys := []interface{}{}
	txoutsspentkeys := []interface{}{}
	for i := range iter.N(int(tx.TxOutCnt)) {
		txoutskeys = append(txoutskeys, fmt.Sprintf("txo:%v:%v", tx.Hash, i))
		txoutsspentkeys = append(txoutsspentkeys, fmt.Sprintf("txo:%v:%v:spent", tx.Hash, i))
	}
	txoutsjson, _ := redis.Strings(c.Do("MGET", txoutskeys...))
	txoutsspentjson, _ := redis.Strings(c.Do("MGET", txoutsspentkeys...))
	for txoindex, txoutjson := range txoutsjson {
		ctxo := new(TxOut)
		err = json.Unmarshal([]byte(txoutjson), ctxo)
		if txoutsspentjson[txoindex] != "" {
			cspent := new(TxoSpent)
			err = json.Unmarshal([]byte(txoutsspentjson[txoindex]), cspent)
			ctxo.Spent = cspent
		}
		tx.TxOuts = append(tx.TxOuts, ctxo)
	}
	return
}
开发者ID:Kefkius,项目名称:btcplex,代码行数:36,代码来源:models.go

示例5: Ping

func (this *testRedis) Ping(pool *redis.Pool) error {
	connection := pool.Get()
	defer connection.Close()

	_, err := connection.Do("PING")
	return err
}
开发者ID:sandstorm,项目名称:mailer-daemon,代码行数:7,代码来源:RedisRepository_test.go

示例6: Deq

func Deq(pool *redis.Pool, latch *utee.Throttle, uid interface{}) ([]byte, error) {
	c := pool.Get()
	defer c.Close()
	defer latch.Release()
	for {
		name := qname(uid)
		k, err := redis.String(c.Do("LPOP", name))
		if err != nil && err != redis.ErrNil {
			continue
		}

		if len(k) == 0 {
			break
		}
		b, err := redis.Bytes(c.Do("GET", k))
		if err != nil && err != redis.ErrNil {
			continue
		}
		if b != nil {
			c.Send("DEL", k)
			continue
		}
	}
	i++
	if i%10000 == 0 {
		log.Println("@success:", i)
	}
	return nil, nil
}
开发者ID:xiaotiejiang888,项目名称:goPraticse,代码行数:29,代码来源:main.go

示例7: AddTXPayloadToQueue

// AddTXPayloadToQueue adds the given TXPayload to the queue.
func AddTXPayloadToQueue(p *redis.Pool, payload models.TXPayload) error {
	var buf bytes.Buffer
	enc := gob.NewEncoder(&buf)
	if err := enc.Encode(payload); err != nil {
		return fmt.Errorf("encode tx-payload for node %s error: %s", payload.DevEUI, err)
	}

	c := p.Get()
	defer c.Close()

	exp := int64(common.NodeTXPayloadQueueTTL) / int64(time.Millisecond)
	key := fmt.Sprintf(nodeTXPayloadQueueTempl, payload.DevEUI)

	c.Send("MULTI")
	c.Send("LPUSH", key, buf.Bytes())
	c.Send("PEXPIRE", key, exp)
	_, err := c.Do("EXEC")

	if err != nil {
		return fmt.Errorf("add tx-payload to queue for node %s error: %s", payload.DevEUI, err)
	}

	log.WithFields(log.Fields{
		"dev_eui":   payload.DevEUI,
		"reference": payload.Reference,
	}).Info("tx-payload added to queue")
	return nil
}
开发者ID:yuseunghyuk,项目名称:loraserver,代码行数:29,代码来源:node.go

示例8: ReclaimSessionID

func ReclaimSessionID(pool *redis.Pool, sessionID ID, authid string, domain string) error {
	conn := pool.Get()
	defer conn.Close()

	sessionKey := fmt.Sprintf("session:%x", sessionID)

	// First, try to claim the session ID.  This tells us if it exists or
	// safely reserves it if it does not.
	reply, err := redis.Int(conn.Do("HSETNX", sessionKey, "domain", domain))
	if err != nil {
		out.Debug("Redis error on key %s: %v", sessionKey, err)
		return err
	} else if reply == 1 {
		// It did not exist before, but now he owns it.
		return nil
	}

	prevDomain, err := redis.String(conn.Do("HGET", sessionKey, "domain"))
	if err != nil {
		out.Debug("Redis error on key %s: %v", sessionKey, err)
		return err
	}

	// Ensure that the new agent owns the claimed session ID.
	if subdomain(authid, prevDomain) {
		return nil
	} else {
		return fmt.Errorf("Permission denied: %s cannot claim %s", authid, sessionKey)
	}
}
开发者ID:exis-io,项目名称:node,代码行数:30,代码来源:freeze.go

示例9: MustFlushRedis

// MustFlushRedis flushes the Redis storage.
func MustFlushRedis(p *redis.Pool) {
	c := p.Get()
	defer c.Close()
	if _, err := c.Do("FLUSHALL"); err != nil {
		log.Fatal(err)
	}
}
开发者ID:yuseunghyuk,项目名称:loraserver,代码行数:8,代码来源:test.go

示例10: ReadMACPayloadTXQueue

// ReadMACPayloadTXQueue reads the full MACPayload tx queue for the given
// device address.
func ReadMACPayloadTXQueue(p *redis.Pool, devAddr lorawan.DevAddr) ([]models.MACPayload, error) {
	var out []models.MACPayload

	c := p.Get()
	defer c.Close()

	key := fmt.Sprintf(nodeSessionMACTXQueueTempl, devAddr)
	values, err := redis.Values(c.Do("LRANGE", key, 0, -1))
	if err != nil {
		return nil, fmt.Errorf("get mac-payload from tx queue for devaddr %s error: %s", devAddr, err)
	}

	for _, value := range values {
		b, ok := value.([]byte)
		if !ok {
			return nil, fmt.Errorf("expected []byte type, got %T", value)
		}

		var pl models.MACPayload
		err = gob.NewDecoder(bytes.NewReader(b)).Decode(&pl)
		if err != nil {
			return nil, fmt.Errorf("decode mac-payload for devaddr %s error: %s", devAddr, err)
		}
		out = append(out, pl)
	}
	return out, nil
}
开发者ID:yuseunghyuk,项目名称:loraserver,代码行数:29,代码来源:node_session.go

示例11: deliver

func deliver(pool *redis.Pool, key string, data map[string]string) (err error) {
	hkey, err := RandomKey(GOOSE_REDIS_REQ_PREFIX, 16)
	if err != nil {
		return
	}

	conn := pool.Get()
	defer conn.Close()

	// Record the request/match.
	for field, val := range data {
		if err = conn.Send("HSET", hkey, field, val); err != nil {
			return
		}
	}

	// Notify any processes blocking on the associated list.
	if err = conn.Send("LPUSH", key, hkey); err != nil {
		return
	}

	// Flush the pipeline.
	if err = conn.Flush(); err != nil {
		return
	}

	// Read all of the replies, but just drop them on the ground.
	for i := 0; i < len(data)+1; i += 1 {
		if _, err = conn.Receive(); err != nil {
			return
		}
	}

	return
}
开发者ID:politician,项目名称:goose,代码行数:35,代码来源:redis.go

示例12: NewRDBpool

// Redis DB Pool
func NewRDBpool(address string) *RDBpool {
	pool := redis.Pool{
		MaxActive: 0,
		MaxIdle:   3,
		Dial: func() (redis.Conn, error) {
			c, err := redis.DialTimeout(
				"tcp",
				address,
				time.Duration(1)*time.Second,
				time.Duration(1)*time.Second,
				time.Duration(1)*time.Second,
			)
			if err != nil {
				return nil, err
			}

			return c, err
		},
	}

	conn := pool.Get()
	defer conn.Close()
	if conn.Err() != nil {
		panic(fmt.Sprintf("Can not connect to redis %s", address))
	}

	return &RDBpool{pool: pool}
}
开发者ID:zhanghjster,项目名称:ChatChat,代码行数:29,代码来源:redis.go

示例13: BenchmarkRedisPool

func BenchmarkRedisPool(b *testing.B) {
	b.StopTimer()
	p := redis.Pool{
		Dial: func() (redis.Conn, error) {
			//			c, err := redis.Dial("tcp", cfg.RedisAddr())
			c, err := redis.Dial("tcp", ":6379")
			if err != nil {
				return nil, err
			}
			// 选择db
			c.Do("SELECT", 11)
			return c, nil
		},

		MaxIdle:   30,
		MaxActive: 30}
	c := p.Get()
	if err := c.Err(); err != nil {
		b.Fatal(err)
	}
	c.Close()
	defer p.Close()
	//	c = p.Get()
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		c = p.Get()
		if _, err := c.Do("PING"); err != nil {
			b.Fatal(err)
		}
		c.Close()
	}
	b.StopTimer()
	c.Close()

}
开发者ID:lkj01010,项目名称:chesssrv,代码行数:35,代码来源:redis_test.go

示例14: DeleteMACPayloadFromTXQueue

// DeleteMACPayloadFromTXQueue deletes the given MACPayload from the tx queue
// of the given device address.
func DeleteMACPayloadFromTXQueue(p *redis.Pool, devAddr lorawan.DevAddr, pl models.MACPayload) error {
	var buf bytes.Buffer
	enc := gob.NewEncoder(&buf)
	if err := enc.Encode(pl); err != nil {
		return fmt.Errorf("gob encode tx mac-payload for node %s error: %s", pl.DevEUI, err)
	}

	c := p.Get()
	defer c.Close()

	key := fmt.Sprintf(nodeSessionMACTXQueueTempl, devAddr)
	val, err := redis.Int(c.Do("LREM", key, 0, buf.Bytes()))
	if err != nil {
		return fmt.Errorf("delete mac-payload from tx queue for devaddr %s error: %s", devAddr, err)
	}

	if val == 0 {
		return fmt.Errorf("mac-payload with reference '%s' is not in tx queue for devaddr %s", pl.Reference, devAddr)
	}

	log.WithFields(log.Fields{
		"dev_eui":   pl.DevEUI,
		"dev_addr":  devAddr,
		"reference": pl.Reference,
	}).Info("mac-payload removed from tx queue")
	return nil
}
开发者ID:yuseunghyuk,项目名称:loraserver,代码行数:29,代码来源:node_session.go

示例15: instanceIsMaster

func instanceIsMaster(pool *redis.Pool, port string) {
	c := pool.Get()
	defer c.Close()

	for {
		master, err := redis.StringMap(c.Do("CONFIG", "GET", "slaveof"))
		if err != nil {
			// Retry connection to Redis until it is back.
			//log.Println(err)
			defer c.Close()
			time.Sleep(time.Second * time.Duration(connectionLostInterval))
			c = pool.Get()
			continue
		}
		for _, value := range master {
			if value != "" {
				// Instance is now a slave, notify.
				if fetchPossible[port] {
					c.Do("PUBLISH", "redis-scouter", "stop")
					fetchPossible[port] = false
					log.Printf("[instance-check-%s] became a slave", port)
				}
			} else {
				// Re-enable metrics.
				if !fetchPossible[port] {
					fetchPossible[port] = true
					log.Printf("[instance-check-%s] became a master", port)
				}
			}
		}
		time.Sleep(time.Second * time.Duration(masterCheckInterval))
	}
}
开发者ID:victorcete,项目名称:redis-scouter,代码行数:33,代码来源:main.go


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