def dump_photos(app): """ Dumps the photos from redis to stdout. """ import simplejson from flask import g from rdrei.utils.redis_fixtures import dump_fixture # As 'closure' to not load simplejson in global space. class _SetSerializer(simplejson.JSONEncoder): def default(self, obj): if isinstance(obj, set): return list(obj) return simplejson.JSONEncoder.default(self, obj) with _prepared_context(app): result = [] result.append(dump_fixture("photos")) for photo in g.db.smembers("photos"): result.append(dump_fixture("photo:" + photo)) result.append(dump_fixture("phototags")) for phototag in g.db.smembers("phototags"): result.append(dump_fixture("phototags:" + phototag)) print(simplejson.dumps(result, cls=_SetSerializer))
def dump_albums(app): """Dumps the albums to stdout.""" import simplejson from flask import g from rdrei.utils.redis_fixtures import dump_fixture with _prepared_context(app): result = [] result.append(dump_fixture("photoalbum")) for i in xrange(1, int(g.db.get("photoalbum"))): key = "photoalbum:" + str(i) if g.db.exists(key): result.append(dump_fixture(key)) print(simplejson.dumps(result))