Ejemplo n.º 1
0
func (p *RemotePtt) queryMemd(types string, keyvalue ...interface{}) (int, error) {
	if 2*len(types) != len(keyvalue) {
		return 0, ErrArgumentCount
	}

	var err error
	var memd *memcache.Connection
	if memd, err = p.connPool.GetConn(); err != nil {
		return 0, err
	}
	defer func() {
		p.connPool.ReleaseConn(memd, err)
	}()

	// Prepare keys to fetch in batch
	keys := make([]string, len(types))
	for i := range keys {
		keys[i] = keyvalue[2*i].(string)
	}

	res, err := memd.Get(keys...)
	if err != nil {
		return 0, err
	}

	// Put results back
	j := 0
	for i, key := range keys {
		var val []byte
		if j < len(res) && key == res[j].Key {
			// Consume the result
			val = res[j].Value
			j++
		}
		if err = setVal(types[i], keyvalue[2*i+1], val); err != nil {
			return i, err
		}
	}

	return len(types), nil
}
Ejemplo n.º 2
0
func (m *MemcacheConnPool) DropConn(c *memcache.Connection) {
	m.drop <- nil
	if c != nil {
		c.Close()
	}
}