美文网首页
github/Show me the code (3)

github/Show me the code (3)

作者: 知识分子中的文盲 | 来源:发表于2016-05-07 21:35 被阅读11次

第 0003 题:将 0001 题生成的 200 个激活码(或者优惠券)保存到 Redis 非关系型数据库中。
sudo apt-get install redis-server sudo pip install redis

import redis

def store_redis(file_path):
pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
r = redis.StrictRedis(connection_pool=pool)
with open(file_path) as f:
for line in f.readlines():
code = line.strip()
r.lpush('code', code)

if name == 'main':
store_redis('active_code.txt')

相关文章

网友评论

      本文标题:github/Show me the code (3)

      本文链接:https://www.haomeiwen.com/subject/uabjrttx.html