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+1 puts meg.value break if i==10 end