Created
September 23, 2014 20:40
-
-
Save jblancett/91a78b8ec040269030e3 to your computer and use it in GitHub Desktop.
migrate cname in redis and mongodb from tsuru 0.6.2 to 0.7.0
This file contains 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
import pymongo, redis, os | |
REDIS_HOST = os.getenv("REDIS_HOST", "localhost") | |
REDIS_PORT = os.getenv("REDIS_PORT", 6379) | |
MONGO_HOST = os.getenv("MONGODB_HOST", "localhost") | |
MONGO_PORT = os.getenv("MONGODB_PORT", 27017) | |
redis = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT) | |
cnames = redis.keys("cname:*") | |
for cname in cnames: | |
if (redis.type(cname) == 'string'): | |
old = redis.get(cname) | |
redis.delete(cname) | |
redis.lpush(cname, old) | |
print "converted %s to list in redis" % cname | |
mongo = pymongo.MongoClient(MONGO_HOST, MONGO_PORT) | |
for app in mongo.tsuru.apps.find(): | |
if (type(app["cname"]) is not list): | |
app["cname"] = [app["cname"]] | |
mongo.tsuru.apps.save(app) | |
print "converted %s cname to list in mongodb" % app["name"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment