Beispiel #1
0
func (r *clientRPC) Delete(conn io.Writer, req *clientRequest) {
	var res api.Response
	if err := r.s.Delete(req.Key); err != nil {
		setError(&res, err)
	}
	api.NewEncoder(conn).Encode(&res)
}
Beispiel #2
0
func (r *clientRPC) AtomicDelete(conn io.Writer, req *clientRequest) {
	var res api.Response
	ok, err := r.s.AtomicDelete(req.Key, kvToLibKV(req.Previous))
	if err != nil {
		setError(&res, err)
	}
	res.Completed = ok
	api.NewEncoder(conn).Encode(&res)
}
Beispiel #3
0
func (r *clientRPC) Exists(conn io.Writer, req *clientRequest) {
	var res api.Response
	exists, err := r.s.Exists(req.Key)
	if err != nil {
		setError(&res, err)
	}
	res.Exists = exists
	api.NewEncoder(conn).Encode(&res)
}
Beispiel #4
0
func (r *clientRPC) AtomicPut(conn io.Writer, req *clientRequest) {
	var res api.Response
	ok, kv, err := r.s.AtomicPut(req.Key, req.Value, kvToLibKV(req.Previous), &libkvstore.WriteOptions{TTL: req.TTL})
	if err != nil {
		setError(&res, err)
	} else {
		res.Completed = ok
		res.KV = libkvToKV(kv)
	}
	api.NewEncoder(conn).Encode(&res)
}
Beispiel #5
0
func (r *clientRPC) List(conn io.Writer, req *clientRequest) {
	var res api.Response
	ls, err := r.s.List(req.Key)
	if err != nil {
		setError(&res, err)
	}

	var apiLs []*api.KVPair
	for _, kv := range ls {
		apiLs = append(apiLs, libkvToKV(kv))
	}
	res.List = apiLs
	api.NewEncoder(conn).Encode(&res)
}