[VOL-5481] - Implement KeyExists API in kv-store
Change-Id: I2ea7196d538596afb6c8bd57af1103df64c83132
Signed-off-by: Sridhar Ravindra <sridhar.ravindra@radisys.com>
diff --git a/pkg/db/backend.go b/pkg/db/backend.go
index bb99970..8c31295 100644
--- a/pkg/db/backend.go
+++ b/pkg/db/backend.go
@@ -179,6 +179,21 @@
return alive
}
+// KeyExists checks if the specified key exists in kv-store or not
+func (b *Backend) KeyExists(ctx context.Context, key string) (bool, error) {
+ span, ctx := log.CreateChildSpan(ctx, "kvs-key-exists")
+ defer span.Finish()
+
+ formattedPath := b.makePath(ctx, key)
+ logger.Debugw(ctx, "checking-key-exists", log.Fields{"key": key, "path": formattedPath})
+
+ keyExists, err := b.Client.KeyExists(ctx, formattedPath)
+
+ b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(err))
+
+ return keyExists, err
+}
+
// List retrieves one or more items that match the specified key
func (b *Backend) List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error) {
span, ctx := log.CreateChildSpan(ctx, "kvs-list")