Browse Source

Merge pull request #5351 from gyuho/allow_null_key

etcdctl/ctlv3: allow empty key
Gyu-Ho Lee 9 năm trước cách đây
mục cha
commit
410c5cd828
2 tập tin đã thay đổi với 11 bổ sung1 xóa
  1. 2 0
      e2e/ctl_v3_kv_test.go
  2. 9 1
      etcdctl/ctlv3/command/get_command.go

+ 2 - 0
e2e/ctl_v3_kv_test.go

@@ -75,6 +75,8 @@ func getTest(cx ctlCtx) {
 		wkv []kv
 	}{
 		{[]string{"key1"}, []kv{{"key1", "val1"}}},
+		{[]string{"", "--prefix"}, kvs},
+		{[]string{"", "--from-key"}, kvs},
 		{[]string{"key", "--prefix"}, kvs},
 		{[]string{"key", "--prefix", "--limit=2"}, kvs[:2]},
 		{[]string{"key", "--prefix", "--order=ASCEND", "--sort-by=MODIFY"}, kvs},

+ 9 - 1
etcdctl/ctlv3/command/get_command.go

@@ -129,10 +129,18 @@ func getGetOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) {
 	opts = append(opts, clientv3.WithSort(sortByTarget, sortByOrder))
 
 	if getPrefix {
-		opts = append(opts, clientv3.WithPrefix())
+		if len(key) == 0 {
+			key = "\x00"
+			opts = append(opts, clientv3.WithFromKey())
+		} else {
+			opts = append(opts, clientv3.WithPrefix())
+		}
 	}
 
 	if getFromKey {
+		if len(key) == 0 {
+			key = "\x00"
+		}
 		opts = append(opts, clientv3.WithFromKey())
 	}