Skip to content

Instantly share code, notes, and snippets.

@babo
Last active November 22, 2015 18:54
Show Gist options
  • Save babo/ccc848dc0735e634bc16 to your computer and use it in GitHub Desktop.
Save babo/ccc848dc0735e634bc16 to your computer and use it in GitHub Desktop.
#!/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()
@skibohemen
Copy link

Thanks for providing this!

/steinar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment