Last active
November 22, 2015 18:54
-
-
Save babo/ccc848dc0735e634bc16 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import redis | |
import pymysql | |
REDIS = 'redis.cache.amazonaws.com' | |
MYSQL = 'my.rds.amazonaws.com' | |
USER = 'whomai' | |
PASSWORD = 'SECRET' | |
DB = 'mdb' | |
def main(): | |
r = redis.Redis(host=REDIS) | |
mdb = pymysql.connect(host=MYSQL, user=USER, password=PASSWORD, database=DB) | |
c = mdb.cursor() | |
done = 0 | |
count = c.execute('SELECT type, id, count FROM SF_showcounter') | |
print('There are {} counters'.format(count)) | |
pattern = 'counters/{}/{}' | |
while True: | |
lines = c.fetchmany(size=100) | |
if not lines: | |
break | |
for r_type, r_id, r_count in lines: | |
r.incrby(pattern.format(r_type, r_id), int(r_count)) | |
print('.', end='') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for providing this!
/steinar