Last active
December 12, 2015 09:59
-
-
Save hnaohiro/4755608 to your computer and use it in GitHub Desktop.
MongoのデータをRedisに移して検索する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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