0

When I set a key in consul, e.g.:

curl -w "\n" -v --request PUT --data value http://127.0.0.1:8500/v1/kv/my-key?cas=1234

How can I get the index for the value I just set? I was surprised to see the response doesn't contain the header X-Consul-Index (why not?).

If I issue another request, e.g.:

curl -w "\n" -v http://127.0.0.1:8500/v1/kv/my-key

I will get the index for the current value but there are two problems with that:

  1. It's a race condition. The key could have been changed in the meantime and I'll get a different index.
  2. It's wasteful, the response should have that info.

What's the correct way of setting a key/value and knowing the index?

Hesky Fisher
  • 1,145
  • 7
  • 14
  • I asked this on the consul forum and got crickets there too: https://discuss.hashicorp.com/t/how-to-get-the-modify-index-of-a-key-value-after-setting-it/56791 – Hesky Fisher Aug 03 '23 at 14:57

0 Answers0