把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