How to get the revision number of couchbase document?

你离开我真会死。 提交于 2019-12-12 04:03:06

问题


I am using the .NET api for couchbase. Just wanted to know how I can get hold of the revision number for the document?

Cheers


回答1:


As Jeff mentioned above what you want to do is use the cas value. This value exists in both Couchbase and memcached specifically for updating the same document from different threads. The cas is just a random number that is changed every time a document is updated. Basically what you want to do is obtain the cas by using the get() API. This will return you a the current value of for the key requested along with the cas value. In your application you can then modify your document and the call the set() API, but make sure to include the cas value. When the server receives a set with a cas value it only updates the document if the cas value matches the one that the server currently has. If the set() operation fails then you know the document has changed and you can get the document again (and remember the new cas value), make your changes, and then try to set() the document again.

http://docs.couchbase.com/couchbase-devguide-2.5/#check-and-set-cas




回答2:


The best solution (without resorting to some low-level unrecommended method that may not even exist) would just be to store the revision as a part of the value, surely? This would also allow it to be read in views, which could offer some utility (e.g. notifying only certain waiting processes/docs when another completes).



来源:https://stackoverflow.com/questions/24694291/how-to-get-the-revision-number-of-couchbase-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!