You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.0 KiB

  1. package weed_server
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/filer"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. )
  7. func (fs *FilerServer) KvGet(ctx context.Context, req *filer_pb.KvGetRequest) (*filer_pb.KvGetResponse, error) {
  8. value, err := fs.filer.Store.KvGet(ctx, req.Key)
  9. if err == filer.ErrKvNotFound {
  10. return &filer_pb.KvGetResponse{}, nil
  11. }
  12. if err != nil {
  13. return &filer_pb.KvGetResponse{Error: err.Error()}, nil
  14. }
  15. return &filer_pb.KvGetResponse{
  16. Value: value,
  17. }, nil
  18. }
  19. // KvPut sets the key~value. if empty value, delete the kv entry
  20. func (fs *FilerServer) KvPut(ctx context.Context, req *filer_pb.KvPutRequest) (*filer_pb.KvPutResponse, error) {
  21. if len(req.Value) == 0 {
  22. if err := fs.filer.Store.KvDelete(ctx, req.Key); err != nil {
  23. return &filer_pb.KvPutResponse{Error: err.Error()}, nil
  24. }
  25. }
  26. err := fs.filer.Store.KvPut(ctx, req.Key, req.Value)
  27. if err != nil {
  28. return &filer_pb.KvPutResponse{Error: err.Error()}, nil
  29. }
  30. return &filer_pb.KvPutResponse{}, nil
  31. }