CouchbaseNetClient KeyExists ignores cas validation

I’m using KeyExists() to minimize the amount of data that I transfer from Couchbase, instead preferring a local cache. The only thing verified for each use is the CAS value which I also store.

So, I call KeyExists(KEY, cas) and, so long as the KEY exists, it always returns success. It does not verify the cas. A simple fix would be:

    public bool KeyExists(string key, ulong cas)
    {
        var result = Observe(key, cas, PersistTo.Zero, ReplicateTo.Zero);
        return (result.Success && (result.Cas == cas))
    }

-H

I don’t think that this is what the method intends. Because if the key exists and the cas doesn’t match, the key still exists! The semantics are different at this method.

Let’s double check with @jmorris on this one, and can you please provide your use case so we can find the ideal solution?

Perhaps, but then what is the point of taking the CAS as a parameter? I’ve obviously been able to easily work around this issue in my code (implementing my own “KeyExists()” in my code, which then calls Observe and interprets the response as I described. But, again, no point in taking CAS if that’s not the expected behavior.

The CAS parameter on the observe method (which is used internally) is needed for PersistTo/ReplicateTo checks, so this is probably the reason why it’s exposed like this. That said, I don’t know the .NET SDK that much so I can say if it is expected to be used by the public and if it’s a bug or intended.

Let’s wait for @jmorris on that one.

unhuman -

To be honest, I am not sure why that method takes a CAS value. I would think the behavior should simply be to check if the key exists, not that it exists and then value hasn’t changed. That being said, it’s using Observe internally which is probably the reason.

Also, the server should be validating the CAS value passed in, not the client. If that method is not honoring the CAS its probably an implementation bug somewhere in the client.

-Jeff