Locking records with python sdk

hey everyone,
first off I want to thank everyone for their help as I work to get up to speed on python/couchbase. Now to my issue I cannot seem to find anywhere how to lock a couchbase record from python for updating.

I would like to lock a record update it and then release the lock, I assume this should be possible with the sdk but I cannot find any examples or documents on it. Again any and all help is appreciated.

thanks

dougc

You can get the document with a lock.

Just search on that page for GetWithLock
https://developer.couchbase.com/documentation/server/current/sdk/dotnet/document-operations.html

thanks for your response that the link is to the .net sdk and not the python one, when I changed dotnet to python in your url I get to the python page but there is no GetWithLock for python, at least none that I can find.

I tried using GetWithLock in python

cb.GetWithLock(custId,TimeSpan(0, 0, 10));

with no success

again thanks

At a glance, the Python syntax is .lock(). I’ll try and have more than a glance when I get chance, but in the meantime I’ve raised DOC-3455 to make sure we get an example in the docs.

thank you, I tried (while patiently waiting)

:slight_smile:

custRec = cb.get.lock(custId);

which is in a try/except block and it hits the except BUT if I remove the .lock the get works

is my syntax correct?

thanks

Hi all. I am on the same question as Douge. Here is what I have tried so far but I may be on the wrong track.
reqLock = cb.lock(custId, ttl=5)
custRec = cb.get(custId)

custRec.value['5'] = "Cincinnati"

I have no idea how to update the record I locked above

cb.unlock(custId, reqLock.cas)