把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