读mongodb简单方法

require 'mongo'
db = Mongo::Connection.new('localhost').db("friendlinks")
city = db.collection('elong_hotel_city')
city.find.each do |line|
  p line
end

ruby 为 mongodb 增加索引

require 'mongo'
db = Mongo::Connection.new.db("qunar")
@coll = db.collection('hotels')
@coll.ensure_index({'cityname'=>1,'id'=>1})

FOR MAC

$ sed -i .bak 's!cache.ruby-lang.org/pub/ruby!ruby.taobao.org/mirrors/ruby!' $rvm_path/config/db

FOR LINUX

$ sed -i 's!cache.ruby-lang.org/pub/ruby!ruby.taobao.org/mirrors/ruby!' $rvm_path/config/db

ActiveRecord::Base.logger = Logger.new(STDOUT)

或者

ActiveRecord::Base.logger = Logger.new('/var/log/xxx.log')

product = Product.first
product.changed? #false
product.save #nothing happens

http://api.rubyonrails.org/classes/ActiveModel/Dirty.html

require 'redis'
r = Redis.new
r.set('key','value123')
r.get('key') # 'value123'
r.del('key') # 1
r.del('key') # 0

http://redis.io/topics/quickstart