Exemplo n.º 1
0
func replace(req *proto.MCRequest, cache *cache.Cache) *proto.MCResponse {
	res := proto.NewResStatus(req.Opcode, proto.STORED)
	if err := cache.Replace(req.Key, req.Value,
		time.Duration(req.Expires)*time.Second); err != nil {
		res = proto.NewResStatus(req.Opcode, proto.NOT_STORED)
	}
	return res
}
Exemplo n.º 2
0
func gets(req *proto.MCRequest, cache *cache.Cache) *proto.MCResponse {
	value, found := cache.Get(req.Key)
	res := proto.NewResFull(req.Opcode, proto.SUCCESS, req.Key, req.Flags, found)
	if found == false {
		res.Status = proto.END
	} else {
		valueb := value.([]byte)
		res.Value = make([]byte, len(valueb))
		copy(res.Value, valueb)
	}
	return res
}
Exemplo n.º 3
0
func delete(req *proto.MCRequest, cache *cache.Cache) *proto.MCResponse {
	cache.Delete(req.Key)
	res := proto.NewResStatus(req.Opcode, proto.DELETED)
	return res
}
Exemplo n.º 4
0
func set(req *proto.MCRequest, cache *cache.Cache) *proto.MCResponse {
	cache.Set(req.Key, req.Value, time.Duration(req.Expires)*time.Second)
	res := proto.NewResStatus(req.Opcode, proto.SUCCESS)
	return res
}