{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/consul/issues/1864","repository_url":"https://api.github.com/repos/hashicorp/consul","labels_url":"https://api.github.com/repos/hashicorp/consul/issues/1864/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/consul/issues/1864/comments","events_url":"https://api.github.com/repos/hashicorp/consul/issues/1864/events","html_url":"https://github.com/hashicorp/consul/issues/1864","id":142646101,"number":1864,"title":"CAS index if no key?","user":{"login":"lud4ik","id":905024,"avatar_url":"https://avatars.githubusercontent.com/u/905024?v=3","gravatar_id":"","url":"https://api.github.com/users/lud4ik","html_url":"https://github.com/lud4ik","followers_url":"https://api.github.com/users/lud4ik/followers","following_url":"https://api.github.com/users/lud4ik/following{/other_user}","gists_url":"https://api.github.com/users/lud4ik/gists{/gist_id}","starred_url":"https://api.github.com/users/lud4ik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lud4ik/subscriptions","organizations_url":"https://api.github.com/users/lud4ik/orgs","repos_url":"https://api.github.com/users/lud4ik/repos","events_url":"https://api.github.com/users/lud4ik/events{/privacy}","received_events_url":"https://api.github.com/users/lud4ik/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-22T13:14:19Z","updated_at":"2016-04-05T05:28:40Z","closed_at":"2016-04-05T05:28:40Z","body":"I perform get, use meta.LastIndex for ModifyIndex in CAS\r\n```\r\n             &api.KVPair{\r\n\t\t\t\tKey:         q.cacheKey,\r\n\t\t\t\tValue:       body,\r\n\t\t\t\tModifyIndex: lastIndex,\r\n\t\t\t},\r\n```\r\nBut if no key exists, it returns some random number for response meta.LastIndex and always fails on CAS operation (false for first param in api).\r\nConsul 0.5.0\r\n```\r\n2016/03/22 13:15:35 [DEBUG] http: Request /v1/kv/service/go-asterisk/flush/originate?consistent=&dc=dc1 (109.407µs)\r\n2016/03/22 13:15:35 [DEBUG] http: Request /v1/kv/service/go-asterisk/flush/originate?cas=531&dc=dc1 (227.414µs)\r\n\r\n```\r\n\r\nIf key is present everything works ok."},"comment":{"url":"https://api.github.com/repos/hashicorp/consul/issues/comments/205652515","html_url":"https://github.com/hashicorp/consul/issues/1864#issuecomment-205652515","issue_url":"https://api.github.com/repos/hashicorp/consul/issues/1864","id":205652515,"user":{"login":"slackpad","id":673509,"avatar_url":"https://avatars.githubusercontent.com/u/673509?v=3","gravatar_id":"","url":"https://api.github.com/users/slackpad","html_url":"https://github.com/slackpad","followers_url":"https://api.github.com/users/slackpad/followers","following_url":"https://api.github.com/users/slackpad/following{/other_user}","gists_url":"https://api.github.com/users/slackpad/gists{/gist_id}","starred_url":"https://api.github.com/users/slackpad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slackpad/subscriptions","organizations_url":"https://api.github.com/users/slackpad/orgs","repos_url":"https://api.github.com/users/slackpad/repos","events_url":"https://api.github.com/users/slackpad/events{/privacy}","received_events_url":"https://api.github.com/users/slackpad/received_events","type":"User","site_admin":false},"created_at":"2016-04-05T05:28:40Z","updated_at":"2016-04-05T05:28:40Z","body":"Hi @lud4ik if you query and don't get a key back the index is set to the last index that modified the KV store, since there's no key present that you are querying (you could use this to do a blocking query to wait for that key to get created, for example). If the key doesn't exist you can use `?cas=0` which means \"create the key only if it isn't already there\". Hope that helps!"}}