Example #1
0
func (c *ShardedClient) release(rawClient ClientShard, conn net2.ManagedConn) {
	if rawClient.IsValidState() {
		conn.ReleaseConnection()
	} else {
		conn.DiscardConnection()
	}
}
Example #2
0
func (c *ShardedClient) getMultiHelper(
	shard int,
	conn net2.ManagedConn,
	connErr error,
	keys []string,
	resultsChannel chan map[string]GetResponse) {

	var results map[string]GetResponse
	if shard == -1 {
		results = make(map[string]GetResponse)
		for _, key := range keys {
			results[key] = NewGetErrorResponse(key, c.unmappedError(key))
		}
	} else if connErr != nil {
		results = make(map[string]GetResponse)
		for _, key := range keys {
			results[key] = NewGetErrorResponse(
				key,
				c.connectionError(shard, connErr))
		}
	} else if conn == nil {
		results = make(map[string]GetResponse)
		for _, key := range keys {
			// NOTE: zero is an invalid version id.
			results[key] = NewGetResponse(key, StatusKeyNotFound, 0, nil, 0)
		}
	} else {
		client := c.newRawClient(shard, conn)
		defer c.release(client, conn)

		results = client.GetMulti(keys)
		if client.IsValidState() {
			getOkByAddr.Add(conn.Key().Address, 1)
		} else {
			getErrByAddr.Add(conn.Key().Address, 1)
		}
	}
	resultsChannel <- results
}