← 返回命令列表

Linux command

consul-kv 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Get a key's value

consul kv get [key]

Put a value

consul kv put [key] [value]

Delete a key

consul kv delete [key]

List keys

consul kv get -keys [prefix/]

Get with recurse

consul kv get -recurse [prefix/]

Export all keys

consul kv export [prefix/] > [backup.json]

Import keys

consul kv import @[backup.json]

说明

consul kv manages Consul's key-value store, a distributed data store for configuration and service discovery. Values can be strings, JSON, or binary data. Part of HashiCorp Consul, the KV store is commonly used for dynamic configuration, feature flags, and service coordination. Keys are organized hierarchically using `/` as a separator, similar to a filesystem path structure. Values can be up to 512 KB in size.

参数

-keys
List only keys, not values.
-recurse
Retrieve all keys with the prefix.
-base64
Encode/decode values as base64.
-detailed
Provide additional metadata about the key.
-separator _STRING_
String to use as separator for key listing (default: "/").
-cas
Perform a Check-And-Set operation (requires -modify-index).
-modify-index _N_
ModifyIndex used by -cas for atomic updates.
-flags _N_
Unsigned integer flag value to associate with the KV pair.
-acquire
Acquire a lock on the key (requires -session).
-release
Release a lock on the key (requires -session).
-session _ID_
Session identifier used with -acquire/-release.
-token _TOKEN_
ACL token for API requests.
-datacenter _DC_
Target datacenter for the request.
-http-addr _ADDRESS_
Address of the Consul agent (default: "http://127.0.0.1:8500").

FAQ

What is the consul-kv command used for?

consul kv manages Consul's key-value store, a distributed data store for configuration and service discovery. Values can be strings, JSON, or binary data. Part of HashiCorp Consul, the KV store is commonly used for dynamic configuration, feature flags, and service coordination. Keys are organized hierarchically using `/` as a separator, similar to a filesystem path structure. Values can be up to 512 KB in size.

How do I run a basic consul-kv example?

Run `consul kv get [key]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -keys do in consul-kv?

List only keys, not values.