第 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')