Skip to content

Instantly share code, notes, and snippets.

@hnaohiro
Last active December 12, 2015 09:59
Show Gist options
  • Save hnaohiro/4755608 to your computer and use it in GitHub Desktop.
Save hnaohiro/4755608 to your computer and use it in GitHub Desktop.
MongoのデータをRedisに移して検索する
# encoding: utf-8
require 'redis'
require 'mongo'
def mongo2redis
redis = Redis.new
redis.flushall
connection = Mongo::Connection.new
db = connection.db('hatena')
coll = db.collection('entries')
coll.find.each do |record|
url = record['link']
content = record['content']
redis.set(content, url)
end
end
def find(s)
redis = Redis.new
redis.keys("*#{s}*").each do |key|
puts redis.get(key)
end
end
mongo2redis
find('hoge')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment