Пример #1
0
func (h *Handler) BFIncr(req *protocol.McRequest, res *protocol.McResponse) error {
	if exist := h.Incr(req.Key); exist {
		res.Response = "1"
	} else {
		res.Response = "0"
	}
	return nil
}
func DefaultGet(req *protocol.McRequest, res *protocol.McResponse) error {
	for _, key := range req.Keys {
		value := dict[key]
		// TODO missed
		res.Values = append(res.Values, protocol.McValue{key, "0", value})
	}
	res.Response = "END"
	return nil
}
Пример #3
0
func (h *Handler) BFGet(req *protocol.McRequest, res *protocol.McResponse) error {
	var b []byte
	for _, key := range req.Keys {
		if exist := h.Get(key); exist {
			b = []byte("1")
		} else {
			b = []byte("0")
		}
		res.Values = append(res.Values, protocol.McValue{key, "0", b})
	}
	res.Response = "END"
	return nil
}
func DefaultDelete(req *protocol.McRequest, res *protocol.McResponse) error {
	count := 0
	for _, key := range req.Keys {
		if _, exists := dict[key]; exists {
			delete(dict, key)
			count++
		}
	}
	if count > 0 {
		res.Response = "DELETED"
	} else {
		res.Response = "NOT_FOUND"
	}
	return nil
}
func DefaultSet(req *protocol.McRequest, res *protocol.McResponse) error {
	key := req.Key
	value := req.Value
	dict[key] = value

	res.Response = "STORED"
	return nil
}
func DefaultIncr(req *protocol.McRequest, res *protocol.McResponse) error {
	key := req.Key
	increment := req.Increment
	var base int64
	if value, exists := dict[key]; exists {
		var err error
		base, err = strconv.ParseInt(string(value), 10, 64)
		if err != nil {
			return err
		}
	}

	value := strconv.FormatInt(base+increment, 10)
	dict[key] = []byte(value)

	res.Response = value
	return nil
}
func DefaultVersion(req *protocol.McRequest, res *protocol.McResponse) error {
	res.Response = "VERSION simple-memcached-0.1"
	return nil
}
func DefaultFlushAll(req *protocol.McRequest, res *protocol.McResponse) error {
	// TODO clear map
	res.Response = "OK"
	return nil
}
Пример #9
0
func (h *Handler) BFVersion(req *protocol.McRequest, res *protocol.McResponse) error {
	res.Response = "VERSION simple-memcached-0.1"
	return nil
}
Пример #10
0
func (h *Handler) BFSet(req *protocol.McRequest, res *protocol.McResponse) error {
	h.Set(req.Key)
	res.Response = "STORED"
	return nil
}