【问题标题】:How do I add a default value to a key in etcd3 if one does not already exist?如果 etcd3 中的键尚不存在,如何为键添加默认值?
【发布时间】:2017-07-26 22:56:10
【问题描述】:

在 etcd2 中,我可以按如下方式填充默认值:

curl -Ss -XPUT "${ETCDCTL_PEERS}/v2/keys/mykey?prevExist=false" -d value=defaultValue

如何使用 etcdv3 实现相同的逻辑?

【问题讨论】:

    标签: etcd3


    【解决方案1】:

    类似这样的:

    etcdctl txn <<<'mod("my_key_exists") > "0"
    
    get next_ip_value
    
    put my_key_exists 1
    put my_key "defaultValue"
    
    '
    

    【讨论】:

      猜你喜欢
      • 2019-04-23
      • 2012-03-22
      • 2014-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2017-06-24
      相关资源
      最近更新 更多