如何获得Couchbase文件的修订号? [英] How to get the revision number of couchbase document?

查看:48
本文介绍了如何获得Couchbase文件的修订号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将.NET api用于Couchbase.只是想知道我如何掌握该文件的修订号?

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

欢呼

推荐答案

正如Jeff上面提到的,您要做的就是使用cas值.Couchbase和memcached中都存在此值,专门用于从不同线程更新同一文档.cas只是一个随机数,每次文档更新时都会更改.基本上,您要做的就是使用get()API获得cas.这将为您返回请求键的当前值以及cas值.然后,您可以在应用程序中修改文档并调用set()API,但请确保包括cas值.当服务器收到带有cas值的集合时,只有在cas值与服务器当前具有的值匹配时,它才更新文档.如果set()操作失败,则说明文档已更改,您可以再次获取文档(并记住新的cas值),进行更改,然后尝试再次设置()文档.

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

这篇关于如何获得Couchbase文件的修订号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆