1. 程式人生 > >如何將csv中內容寫入到redis中

如何將csv中內容寫入到redis中

import csv
import redis
r = redis.StrictRedis(host='47.115.124.39', port=6379, db=1, password='123456')

with open('tets.csv', 'rt', encoding='utf-8') as csvfile:
    reader = csv.DictReader(csvfile)

    for row in reader:
        name = row['name']
        id = row['id']
        print(row)
        r.set(name,id)  #將內容寫入redis