12
返回列表 发新帖
楼主: jieforest

Cassandra使用入门

[复制链接]
论坛徽章:
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
11#
 楼主| 发表于 2013-1-1 21:38 | 只看该作者
Next, add some data to the CarDataStore keyspace like so:
  1. [default@unknown] use CarDataStore;
  2. Authenticated to keyspace: CarDataStore
  3. [default@CarDataStore] set Cars['Prius']['make'] = 'toyota';
  4. Value inserted.
  5. [default@CarDataStore] set Cars['Prius']['model'] = 'prius 3';
  6. Value inserted.
  7. [default@CarDataStore] set Cars['Corolla']['make'] = 'toyota';
  8. Value inserted.
  9. [default@CarDataStore] set Cars['Corolla']['model'] = 'le';
  10. Value inserted.
  11. [default@CarDataStore] set Cars['fit']['make'] = 'honda';
  12. Value inserted.
  13. [default@CarDataStore] set Cars['fit']['model'] = 'fit sport';
  14. Value inserted.
  15. [default@CarDataStore] set Cars['focus']['make'] = 'ford';
  16. Value inserted.
  17. [default@CarDataStore] set Cars['focus']['model'] = 'sel';
  18. Value inserted.
复制代码
The set of commands illustrated is a way to add data to Cassandra. Using this command, a name-value pair or column value is added within a row, which in turn is defined in a ColumnFamily in a keyspace. For example, set Cars['Prius']['make'] = 'toyota', a name-value pair: 'make' = 'toyota' is added to a row, which is identified by the key 'Prius'. The row identified by 'Prius' is part of the Cars ColumnFamily. The Cars ColumnFamily is defined within the CarDataStore, which you know is a keyspace.

使用道具 举报

回复
论坛徽章:
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
12#
 楼主| 发表于 2013-1-1 21:38 | 只看该作者
Once the data is added, you can query and retrieve it. To get the name-value pairs or column names and values for a row identified by Prius, use the following command: get Cars['Prius']. The output should be like so:
  1. [default@CarDataStore] get Cars['Prius'];
  2. => (column=make, value=746f796f7461, timestamp=1301824068109000)
  3. => (column=model, value=70726975732033, timestamp=1301824129807000)
  4. Returned 2 results.
复制代码
Be careful while constructing your queries because the row-keys, column-family identifiers, and column keys are case sensitive. Therefore, passing in 'prius' instead of 'Prius' does not return any name-value tuples. Try running get Cars['prius'] via the CLI. You will receive a response that reads Returned 0 results. Also, before you query, remember to issue use CarDataStore to make CarDataStore the current keyspace.

使用道具 举报

回复
论坛徽章:
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
13#
 楼主| 发表于 2013-1-2 22:21 | 只看该作者
To access just the 'make' name-value data for the 'Prius' row you could query like so:
  1. [default@CarDataStore] get Cars['Prius']['make'];
  2. => (column=make, value=746f796f7461, timestamp=1301824068109000)
复制代码
Cassandra data sets can support richer data models than those shown so far and querying capabilities are also more complex than those illustrated, but I will leave those topics for a later chapter. For now, I am convinced you have had your first taste.

After walking through two simple examples, one that involved a document store, MongoDB, and another that involved a column database, Apache Cassandra, you may be ready to start interfacing with these using a programming language of your choice.

使用道具 举报

回复
论坛徽章:
26
2009新春纪念徽章
日期:2009-01-04 14:52:28咸鸭蛋
日期:2011-11-13 14:16:262012新春纪念徽章
日期:2012-01-04 11:51:22紫蛋头
日期:2012-02-02 13:13:42玉石琵琶
日期:2012-02-21 15:04:38蛋疼蛋
日期:2012-03-09 08:25:45奥运纪念徽章
日期:2012-11-27 15:37:34复活蛋
日期:2012-12-07 13:05:172013年新春福章
日期:2013-02-25 14:51:242014年世界杯参赛球队:西班牙
日期:2014-06-26 12:03:53
14#
发表于 2013-2-2 06:43 | 只看该作者
请问这篇文章是原创吗?

谢谢!

使用道具 举报

回复

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

本版积分规则 发表回复

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