温馨提示×

如何把csv数据导入redis

小新
460
2021-02-22 10:37:32
栏目: 云计算

如何把csv数据导入redis

把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

0