rails应用中各数据平台的对接
生活随笔
收集整理的這篇文章主要介紹了
rails应用中各数据平台的对接
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.mongo
#Gemfile添加如下兩個gem包gem 'mongoid', '~> 5.1.0' gem 'mongo', '~> 2.4’ @client = Mongo::Client.new([host1,host2],:database=>'database_name',:user=>"user_name",:password=>"password")
@db = @client[:database_name].database
@collection_names = @db.collection_names
@collection_names.each do |collection_name|
i=0
@db[collection_name.to_sym].find.each do |x|
puts x
i = i + 1
break if i == 10
end
end
?
2.redis
$redis = Redis.new(:host => "host", :port => 6379, :db => 2, :password=>"password")$redis.keys
?
3.elasticsearch?
gem 'elasticsearch' gem 'elasticsearch-rails' gem 'elasticsearch-model' $elastic = Elasticsearch::Client.new hosts: [{ host: 'host1',port: '9200',user: 'elastic',password: 'password'},{host: 'host1',port: '9200',user: 'elastic',password: 'password'}], randomize_hosts: true, log: false,send_get_body_as: "post"Elasticsearch::Model.client = $elastic
$elastic.search index:"index_name"
?
4.kafka
gem 'ruby-kafka', '~> 0.5.0' kafka = Kafka.new(seed_brokers:["host:9092"]) consumer = kafka.consumer(:group_id=>"100") consumer.subscribe("topic_name") i=0 consumer.each_message do |meg|puts i=i+1puts meg.valuebreak if i==10 end?
轉(zhuǎn)載于:https://www.cnblogs.com/xiaoff/p/8398730.html
總結(jié)
以上是生活随笔為你收集整理的rails应用中各数据平台的对接的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php$_GET 变量
- 下一篇: webpack学习1-打包