What is the key value storage in couch base

只谈情不闲聊 提交于 2020-01-04 02:53:25

问题


I am new with coucbase,i have some doubt regarding the key value storage in couchbase. Normally we store data as document. I need clarification for bellow queries ,

  • What is the difference between document type and key-value type?
  • How can i achieve key - value storage ? Can you explain with a small example.
  • what is the benefit of storing as key-value?

回答1:


  • What is the difference between document type and key-value type?

In Couchbase you can store any key/value pairs. At this level keys and values are just byte arrays. However, if the value you store happens to be valid JSON, then there is additional functionality (such as views) that become available. You can mix and match within the same bucket. Sometimes its useful to use integer counters, or comma-delimited string lists along side regular JSON documents in the same bucket. Note however that the Couchbase Elasticsearch adapter ONLY works with JSON documents. If you store plain key/value items in a bucket, they will be ignored by the Elasticsearch adapter.

  • How can i achieve key - value storage ? Can you explain with a small example.

        // Connect to localhost or to the appropriate     
        URIuris.add(URI.create("http://localhost:8091/pools"));
        CouchbaseClient client = null;
        client = new CouchbaseClient(uris, "streams", "");
        client.add("1234", "xxx");
        client.replace("1234", "1234");
        Object data = client.get("1234");
        System.out.println(data.toString());
        client.delete("1234");
    
  • what is the benefit of storing as key-value?

Typically the benefit is maximum performance for a couple of reasons.

  1. you don't need to JSON encode/decode the value
  2. operations like Incr() only work on values which are integers
  3. operations like Append() only work on values which are strings
  4. using these operations are special case operations that can allow you to avoid Get/Set/Cas retry operations


来源:https://stackoverflow.com/questions/26527466/what-is-the-key-value-storage-in-couch-base

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