楼主: jieforest

Couchbase API数据访问Guide

[复制链接]
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
31#
 楼主| 发表于 2013-3-14 11:17 | 只看该作者
Set Operations

The set method stores a value to the database with a specified key, overwriting existing content if it exists (see add/replace above).
  1. client.set(key, value, options = {})
  2. client.set[key, options = {}] = value
复制代码
options:
  1. :ttl         [Fixnum, Integer] Time to Live in seconds [optional]
  2. :flags       [Fixnum] Flags that you want to store/retrieve [optional]
  3. :cas         [Fixnum] Optimistic locking for update control, must match the document cas in Couchbase to succeed
  4. :format      [:document, :plain, :marshal] Explicit format setting, :plain for strings, :document for Hash(JSON), :marshal to use Marshal. load and Marshal.dump; format is :document by default
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
32#
 楼主| 发表于 2013-3-15 08:48 | 只看该作者
Simple Get Operations
  1. val = client.get(key, options = {})
  2. val = client[“key”]
复制代码
Extended Tuple Get Operations
  1. val, flags, cas = client.get(key, :extended => true)
  2. val, flags, cas = client[“key”, :extended => true]
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
33#
 楼主| 发表于 2013-3-15 08:50 | 只看该作者
Multi-Get Operations
  1. val_array = client.get(keys)
  2. val_hash = client.get(keys, :assemble_hash => true)
复制代码
options:
  1. :extended         [String, Symbol] Key used to reference the value
  2. :quiet            [true, false] Return nil for missing keys default, or false to Return Couchbase::Error::KeyNotFound for missing key
  3. :ttl              [Fixnum, Integer] Get and Touch, :ttl will also reset the TTL at the same time as the get (seconds)
  4. :lock             Lock the document, true to use default lock timeout, or integer for number of seconds to lock
  5. :format           [:document, :plain, :marshal] Explicit format setting, :plain for strings, :document for Hash(JSON), :marshal to use Marshal.load and Marshal.dump
  6. :assemble_hash    [true, false] For Multi-Get, will return a Hash keyed on the document keys instead of default of array
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
34#
 楼主| 发表于 2013-3-15 08:51 | 只看该作者
GETTING STATS FROM COUCHBASE

Obtain stats from all servers for the connection (bucket)
  1. client.stats
  2. client.stats[“stats”]
复制代码
To fetch memory stats
  1. client.stats(:memory)
复制代码
Parameters:
  1. stat Individual stat string (i.e. "curr_items")
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
35#
 楼主| 发表于 2013-3-15 08:51 | 只看该作者
DELETING AND UPDATING DATA

To delete keys/values
  1. client.delete(key)
复制代码
Atomic Counter Operations

Atomic Counters are only atomic per cluster, but are useful for many different patterns and numeric data. They are unsigned positive integers.

You cannot use atomic operations on floats or objects or arrays.
  1. client.incr(key, delta, options = {})
  2. client.decr(key, delta, options = {})
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
36#
 楼主| 发表于 2013-3-15 08:53 | 只看该作者
options:
  1. delta        [Fixnum] Amount to incr/decr, default is 1, can be up to 64 bits
  2. :create      [true, false] If set to true, if key doesn’t exist, initializes to zero but doesn’t increment, can be combined with :initial
  3. :initial     [Fixnum, Unsigned Integer] Sets initial value if key doesn’t exist, doesn’t increment the initial value!
  4. :extended    [true, false] Returns [value, cas] tuple instead of just value
  5. :ttl         [Fixnum, Integer] Sets TTL, doesn’t alter existing TTL, will only be applied to a new item created via :create and/or :initial
复制代码
Touch Operations

Reset the TTL expiration on one or more keys explicitly with the touch command, can also be done with a get command.
  1. client.touch(key, ttl)
  2. client.touch({“key1”=> ttl1, “key2” => ttl2})
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
37#
 楼主| 发表于 2013-3-16 14:30 | 只看该作者
Durability Requirements

Observe the state of the keys on all the nodes or using :replicated and ersisted it allows to set up the waiting rule.
  1. client.observe(*keys, options = {})
  2. client.observe_and_wait(*keys, options = {})
复制代码
Non-JSON Operations

For non-json values, prepend and append can concatenate to existing values accordingly. Defaults tolain format for encoder/decoder.
  1. client.prepend(key, value)
  2. client.append(key, value)
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
38#
 楼主| 发表于 2013-3-17 12:54 | 只看该作者
QUERYING DATA

With Couchbase Server 2.0, you can create Indexes through Map/Reduce functions.

http://www.couchbase.com/docs/co ... ouchbase-views.html

Create Design Doc Object

Refer to the design_doc by name, the Views are an array of view names, as well as functions defined by name.
  1. ddoc = client.design_docs[‘design_doc_name’]
  2. ddoc.views #=> [‘view_name’, ‘view_name_2’, …]
复制代码
Use dot notation for accessing the view by your defined view name and pass in options for query parameters:
  1. ddoc.view_name(params = {}).each do |doc|
  2. # do stuff with docs
  3. end
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
39#
 楼主| 发表于 2013-3-17 12:57 | 只看该作者
options:
  1. :include_docs        [true, false] Perform get with key on rows returned with key (non-reduce)
  2. :descending          [true, false], reverse order of returned rows
  3. :key                 [String, Fixnum, Hash, Array] Return only rows with index key that match :key, simple and compound keys can be used (JSON encoded)
  4. :keys                [Array] Return only rows that match array of keys (see :key), both simple and compound keys (JSON encoded)
  5. :startkey            [String, Fixnum, Hash, Array] Range query from :start_key to :end_key (JSON encoded)
  6. :endkey              [String, Fixnum, Hash, Array] Range query from :start_key to :end_key (JSON encoded)
  7. :startkey_docid      [String] Document id to start with (to allow pagination for duplicate startkeys
  8. :endkey_docid        [String] Last document id to include in the output (to allow pagination for duplicate startkeys)
  9. :inclusive_end       [true, false] If true, specificed end key is included in result
  10. :limit               [Fixnum] Limit the results returned
  11. :skip                [Fixnum] Skip a number of results before returning (can be used with :limit to page through results)
  12. :reduce              [true, false] Perform the reduce function defined in the view. If there is no reduce defined default is false and setting to true will return error.
  13. :group               [true, false] Groups results using the view defined reduce function
  14. :group_level         [Fixnum] Sets the grouping level for compound keys
  15. :stale               [:false, :update_after, :ok] Consistency setting, :false initiates Design Document to update indexes before returning results, :update_after updates indexes after returning results, :ok doesn’t trigger indexers and returns existing indexed results
  16. :body                [Hash] Takes same parameters as options but does it as a POST if the query has many parameters or is complex
  17. :on_error            [:continue, :stop] Behavior setting if an error occurs during view query
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
40#
 楼主| 发表于 2013-3-17 12:58 | 只看该作者
.NET CONNECTING TO COUCHBASE
  1. var config = new CouchbaseClientConfiguration();
  2. config.Urls.Add(new Uri(“http://<hostname>:8091/pools/”));
  3. config.Bucket = “<bucketname>”;
  4. var client = new CouchbaseClient(config);
复制代码
WRITING DATA

Based on the storemode, Store and ExecuteStore may be an Add, Replace or Set operation. Execute API’s return the operation result.

Store Operations
  1. object.Store(storemode, key, value)
  2. object.Store(storemode, key, value, validfor)
  3. object.Store(storemode, key, value, expiresat)
复制代码

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表