2020-09-02 12:58:57 +08:00
|
|
|
package etcd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
2020-09-02 12:58:57 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (store *EtcdStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
|
|
|
|
|
2023-05-19 14:08:56 +08:00
|
|
|
_, err = store.client.Put(ctx, store.etcdKeyPrefix + string(key), string(value))
|
2020-09-02 12:58:57 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("kv put: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *EtcdStore) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
|
|
|
|
|
2023-05-19 14:08:56 +08:00
|
|
|
resp, err := store.client.Get(ctx, store.etcdKeyPrefix + string(key))
|
2020-09-02 12:58:57 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("kv get: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(resp.Kvs) == 0 {
|
|
|
|
return nil, filer.ErrKvNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Kvs[0].Value, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *EtcdStore) KvDelete(ctx context.Context, key []byte) (err error) {
|
|
|
|
|
2023-05-19 14:08:56 +08:00
|
|
|
_, err = store.client.Delete(ctx, store.etcdKeyPrefix + string(key))
|
2020-09-02 12:58:57 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("kv delete: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|