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.

44 lines
894 B

  1. package etcd
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/seaweedfs/seaweedfs/weed/filer"
  6. )
  7. func (store *EtcdStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
  8. _, err = store.client.Put(ctx, store.etcdKeyPrefix + string(key), string(value))
  9. if err != nil {
  10. return fmt.Errorf("kv put: %v", err)
  11. }
  12. return nil
  13. }
  14. func (store *EtcdStore) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
  15. resp, err := store.client.Get(ctx, store.etcdKeyPrefix + string(key))
  16. if err != nil {
  17. return nil, fmt.Errorf("kv get: %v", err)
  18. }
  19. if len(resp.Kvs) == 0 {
  20. return nil, filer.ErrKvNotFound
  21. }
  22. return resp.Kvs[0].Value, nil
  23. }
  24. func (store *EtcdStore) KvDelete(ctx context.Context, key []byte) (err error) {
  25. _, err = store.client.Delete(ctx, store.etcdKeyPrefix + string(key))
  26. if err != nil {
  27. return fmt.Errorf("kv delete: %v", err)
  28. }
  29. return nil
  30. }