六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 892|回复: 0

在Ruby把MySQL做NoSQL用 Friendly简介

[复制链接]

升级  40.8%

220

主题

220

主题

220

主题

进士

Rank: 4

积分
704
 楼主| 发表于 2013-1-25 21:09:02 | 显示全部楼层 |阅读模式
Friendly是一个github上的一个插件,起源是因为FriendFeed把MySQL做NoSQL的用,具体参见这篇:
http://bret.appspot.com/entry/how-friendfeed-uses-mysql


  Friendly就是这样的作用,把MySQL变成一个文件数据库来用。NoSQL日趋狂热,schemaless是其中一个原因。客户端的改变可以将MySQL达到同样目的。下面是简单的介绍:



安装friendly


sudo gem install friendly

在Rails里



#environment.rb:    config.gem "friendly"

#and create a config/friendly.yml:development:  :adapter:  "mysql"  :host:     "localhost"  :user:     "root"  :password: "swordfish"  :database: "friendly_development"

没有使用Rails:
Friendly.configure :adapter  => "mysql",                   :host     => "localhost",                   :user     => "root",                   :password => "swordfish",                   :database => "playing_with_friendly"

创建Model


class BlogPost  include Friendly::Document     attribute :author, String  attribute :title,  String  attribute :body,   Stringend

创建Table

#script/console:Friendly.create_tables!

索引

class BlogPost  include Friendly::Document     attribute :author, String  attribute :title,  String  attribute :body,   String     indexes :author  indexes :created_atend     

#Run create_tables again and the index tables will be created for you.Friendly.create_tables!

创建Objects

#With familiar ActiveRecord syntax:BlogPost.create :author => "James Golick",                :title  => "Friendly has familiar syntax.",                :body   => "So, there's very little learning curve."

查询

BlogPost.all(:author => "James Golick")

#Most recent posts:BlogPost.all(:order! => :created_at.desc)

缓存
#Install the memcached gem:sudo gem install memcached#配置 Friendly:Friendly.cache = Friendly::Memcached.new(Memcached.new)#Configure your model to cache:class BlogPost  include Friendly::Document     attribute :author, String  attribute :title,  String  attribute :body,   String     indexes :author  indexes :created_at     caches_by :idend
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表