Esempio n. 1
0
func (mc *Client) sendAck(pkt *gomemcached.MCRequest) (int, error) {
	res := gomemcached.MCResponse{
		Opcode: pkt.Opcode,
		Opaque: pkt.Opaque,
		Status: gomemcached.SUCCESS,
	}
	return res.Transmit(mc.conn)
}
Esempio n. 2
0
func vbRGet(v *VBucket, w io.Writer, req *gomemcached.MCRequest) (
	res *gomemcached.MCResponse) {
	// From http://code.google.com/p/memcached/wiki/RangeOps
	// Extras field  Bits
	// ------------------
	// End key len	 16
	// Reserved       8
	// Flags          8
	// Max results	 32

	res = &gomemcached.MCResponse{
		Opcode: req.Opcode,
		Cas:    req.Cas,
	}

	extras := make([]byte, 4)

	visitRGetResults := int64(0)
	visitOutgoingValueBytes := int64(0)

	visitor := func(i *item) bool {
		if bytes.Compare(i.key, req.Key) >= 0 {
			// TODO: Need to hide expired items from range scan.
			binary.BigEndian.PutUint32(extras, i.flag)
			r := gomemcached.MCResponse{
				Opcode: req.Opcode,
				Key:    i.key,
				Cas:    i.cas,
				Extras: extras,
				Body:   i.data,
			}
			err := r.Transmit(w)
			if err != nil {
				res = &gomemcached.MCResponse{Fatal: true}
				return false
			}
			visitRGetResults++
			visitOutgoingValueBytes += int64(len(i.data))
		}
		return true
	}

	if err := v.ps.visitItems(req.Key, true, visitor); err != nil {
		res = &gomemcached.MCResponse{Fatal: true}
	}

	atomic.AddInt64(&v.stats.RGets, 1)
	atomic.AddInt64(&v.stats.RGetResults, visitRGetResults)
	atomic.AddInt64(&v.stats.OutgoingValueBytes, visitOutgoingValueBytes)

	return res
}
Esempio n. 3
0
func transmitResponse(o io.Writer, res *gomemcached.MCResponse) (err error) {
	return res.Transmit(o)
}