楼主: 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
21#
 楼主| 发表于 2013-3-12 15:08 | 只看该作者
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
22#
 楼主| 发表于 2013-3-13 13:24 | 只看该作者
.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)
复制代码

使用道具 举报

回复
论坛徽章:
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
23#
 楼主| 发表于 2013-3-13 13:26 | 只看该作者
ExecuteStore Operations
  1. object.ExecuteStore(storemode, key, value)
  2. object.ExecuteStore(storemode, key, value, expiresat)
  3. object.ExecuteStore(storemode, key, value, validfor)
  4. object.ExecuteStore(storemode, key, value, ReplicateTo)
  5. object.ExecuteStore(storemode, key, value, PersistTo)
  6. object.ExecuteStore(storemode, key, value, PersistTo,
  7. ReplicateTo)
复制代码
Parameters:
  1. String key             Key used to reference the value.
  2. Object value           Value to be stored
  3. StoreMode storemode    Storage mode for a given key/value pair can be Add, Replace or Set.
  4. Timespan validfor      Expiry timespan (in seconds) for key
  5. DateTime expiresat     Explicit expiry time for key
  6. Enum PersistsTo        Persist to one or more replicas. Master plus one, two, three replicas
  7. Enum ReplicateTo       Replicate to zero or more replicas .NET
复制代码

使用道具 举报

回复
论坛徽章:
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
24#
 楼主| 发表于 2013-3-13 13:28 | 只看该作者
READING DATA

Get Operations
  1. object.Get(key, expiry)
  2. object.ExecuteGet(key, expiry)
  3. object.ExecuteGet(key)
  4. object.ExecuteGet(keyarray)
  5. object.Get(key)
  6. object.Get(keyarray)
  7. object.GetWithCas(key)
复制代码
Parameters:
  1. String key               Key used to reference the value. The key cannot contain control characters or whitespace
  2. object expiry            Expiry time for the key in seconds. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch)
  3. List <string> keyarray   Array of keys used to reference one or more values
复制代码

使用道具 举报

回复
论坛徽章:
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
25#
 楼主| 发表于 2013-3-13 13:29 | 只看该作者
UPDATING DATA

Update existing information on the server:

  1. object.Append(key, value)
  2. object.Append(key, casvalue, value)
  3. object.ExecuteAppend(key, value)
  4. object.ExecuteAppend(key, casvalue, value)
  5. object.Cas(storemode, key, value)
  6. object.Cas(storemode, key, value, casunique)
  7. object.Cas(storemode, key, value, validfor, casunique)
  8. object.ExecuteCas(storemode, key, value)
  9. object.ExecuteCas(storemode, key, value, casunique)
  10. object.ExecuteCas(storemode, key, value, expiresat, casunique)
  11. object.ExecuteCas(storemode, key, value, validfor, casunique)
  12. object.Decrement(key, defaultvalue, offset)
  13. object.Decrement(key, defaultvalue, offset, casunique)
  14. object.Decrement(key, defaultvalue, offset, expiresat, casunique)
  15. object.Decrement(key, defaultvalue, offset, validfor, casunique)
  16. object.Decrement(key, defaultvalue, offset, expiresat)
  17. object.Decrement(key, defaultvalue, offset, validfor)
  18. object.Decrement(key, defaultvalue, offset)
  19. object.Decrement(key, defaultvalue, offset, casunique)
  20. object.Decrement(key, defaultvalue, offset, validfor, casunique)
  21. object.Decrement(key, defaultvalue, offset, expiresat)
  22. object.Decrement(key, defaultvalue, offset, validfor)
  23. object.ExecuteDecrement(key, defaultvalue, offset)
  24. object.ExecuteDecrement(key, defaultvalue, offset, casunique)
  25. object.ExecuteDecrement(key, defaultvalue, offset, expiresat, casunique)
  26. object.ExecuteDecrement(key, defaultvalue, offset, validfor, casunique)
  27. object.ExecuteDecrement(key, defaultvalue, offset, expiresat)
  28. object.ExecuteDecrement(key, defaultvalue, offset, validfor)
  29. object.ExecuteRemove(key)
  30. object.Remove(key)
  31. object.ExecuteIncrement(key, defaultvalue, offset)
  32. object.ExecuteIncrement(key, defaultvalue, offset, casunique)
  33. object.ExecuteIncrement(key, defaultvalue, offset, expiresat, casunique)
  34. object.ExecuteIncrement(key, defaultvalue, offset, validfor, casunique)
  35. object.ExecuteIncrement(key, defaultvalue, offset, expiresat)
  36. object.ExecuteIncrement(key, defaultvalue, offset, validfor)
  37. object.Increment(key, defaultvalue, offset)
  38. object.Increment(key, defaultvalue, offset, casunique)
  39. object.Increment(key, defaultvalue, offset, expiresat, casunique)
  40. object.Increment(key, defaultvalue, offset, validfor, casunique)
  41. object.Increment(key, defaultvalue, offset, expiresat)
  42. object.Increment(key, defaultvalue, offset, validfor)
  43. object.ExecutePrepend(key, value)
  44. object.ExecutePrepend(key, casunique, value)
  45. object.Prepend(key, value)
  46. object.Prepend(key, casunique, value)
  47. object.Touch(key, expiry)
复制代码

使用道具 举报

回复
论坛徽章:
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
26#
 楼主| 发表于 2013-3-13 13:31 | 只看该作者
Parameters:
  1. String key               Key used to reference the value.
  2. Object value             Value to be stored
  3. StoreMode storemode      Storage mode for a given key/value pair mode for a given key/value pair
  4. Timespan validfor        Expiry timespan (in seconds) for key
  5. DateTime expiresat       Explicit expiry time for key
  6. Object defaultvalue      Value to be stored if the key does not exists
  7. offset                   Integer offset value to increment or decrement (default 1)
  8. casunique                Unique value used to verify a key/valuecombination
复制代码
QUERYING DATA

With Couchbase Server 2.0, you can add views and query those views using your applications.
Create a view object to be used when querying a view :
  1. GetView(designName, viewName)
复制代码

使用道具 举报

回复
论坛徽章:
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
27#
 楼主| 发表于 2013-3-14 11:11 | 只看该作者
Parameters:
  1. String ddocname       Design document name
  2. String viewname       View name within a design document
复制代码
Then create a new query object to be used when querying the view:
  1. Query.new()
  2. Query query = new Query();
复制代码
Once the view and query objects are available, the results of the server view can be accessed using:
  1. client.query(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
28#
 楼主| 发表于 2013-3-14 11:13 | 只看该作者
Parameters:
  1. View view              View object associated with a server view
  2. Query query            Query object associated with a server view
复制代码
Before accessing the view, a list of options can be set with the query object:

query.setKey(String key) to set the key to query in the view
query.setKey(ComplexKey key) to set the key to query in the view
query.setRangeStart(String startKey) to set the starting key
query.setRangeStart(ComplexKey startKey) to set the starting key
query.setRangeEnd(String endKey) to set the ending key
query.setRangeEnd(ComplexKey endKey) to set the ending key
query.setRange(String startKey, String endKey) to set a range
query.setRange(ComplexKey startKey, ComplexKey endKey)
query.setDescending(boolean descending) to sort in descending order
query.setIncludeDocs(boolean include) to include the JSON doc
query.setReduce(boolean reduce) execute the reduce function
query.setStale(Stale reduce) set to OK will not refresh the view even if it is stale, set to UPDATE_AFTER will update the view after the stale result is returned, FALSE will update the view and return the latest results.

The format of the returned information of the query method is:
ViewResponse or any of the other inherited objects such as
ViewResponseWithDocs, ViewResponseNoDocs, ViewResponseReduced.

The ViewResponse method provides an iterator() method for iterating through the rows as a ViewRow interface. The ViewResponse method also provides a getMap() method where the result is available as a map.

使用道具 举报

回复
论坛徽章:
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
29#
 楼主| 发表于 2013-3-14 11:15 | 只看该作者
本帖最后由 jieforest 于 2013-3-14 11:15 编辑

RUBY CONNECTING TO COUCHBASE
  1. client = Couchbase.connect(url, options = {});
  2. client = Couchbase.connect(options = {});
复制代码
Hash Parameters:

  1. :hostname             IP address for Couchbase Node (String)
  2. :bucket               Bucket name (String) [optional, default is ‘default’]
  3. :password             SASL password for Bucket (String) [optional]
  4. :nodelist             Array of IP’s for Couchbase Nodes ([String]) like [’12.34.56.78:8091’, ’12.34.56.79’]
复制代码

  1. client = Couchbase.bucket
复制代码
There is a shared single instance of the Couchbase connection object in the Couchbase-model gem and can be used once connected, or when settings are specified in /config/couchbase.yml, which connects on Rails startup.

使用道具 举报

回复
论坛徽章:
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
30#
 楼主| 发表于 2013-3-14 11:16 | 只看该作者
WRITING AND UPDATING DATA

Add Operations


The add method adds a value to the database with the specified key, but will fail (Couchbase::Error::KeyExists) if the key already exists in the database.
  1. client.add(key, value, options = {})
  2. client.add[key, options = {}] = value
复制代码
Replace Operations

The replace method will replace an existing key with a new value but will fail (Couchbase::Error::NotFound) if the key does not exist in the database.
  1. client.replace(key, value, options = {})
  2. client.replace[key, options = {}] = value
复制代码

使用道具 举报

回复

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

本版积分规则 发表回复

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