ReactiveCouchbase / ReactiveCouchbase-core

Core library for ReactiveCouchbase
Apache License 2.0
64 stars 28 forks source link

Optimistic update #81

Closed ruioliveiras closed 7 years ago

ruioliveiras commented 7 years ago

How can i do a optimistic update with this driver?

By an optimistic update I mean something like this:

def update_email(cb, user_id, email):
    while True:
        result = cb.get(user_id)
        user_doc = result.value
        user_doc['email'] = email
        cb.upsert(user_id, user_doc, cas=result.cas)
        break # Mutation succeeded
    except KeyExistsError:
        # This means the CAS has been modified. We still need to
        # insert the email field, but do not want to override new changes
        continue

Has can be found on couchbase documentation, here: https://developer.couchbase.com/documentation/server/4.5/sdk/concurrent-mutations-cluster.html

Best regards, nice library.