使用Windows版本的Redis-cli在Redis中加载CSV文件吗? [英] Load CSV file in Redis using Redis-cli of Windows version?
问题描述
我浏览了许多网址,例如 how导入".csv"数据文件存储到Redis数据库中,并决定在进行大量网络搜索后将这些问题放在此处.
I went through many urls like how to import a ".csv " data-file into the Redis database and decided to put the questions here after lot of web searching.
我有employee.csv
文件,希望使用redis-cli
导入该文件.我正在使用Redis server
的Windows版本3.2.100
.
I've employee.csv
file and looking to import that file using the redis-cli
. I am using windows version 3.2.100
of Redis server
.
employee.csv
employee.csv
SET "employee_1" "1, John Smith, 40, Male, John, 10000"
SET "employee_2" "2, Marco Polo, 43, Male, Marco, 10000"
....
SET "employee_1999999" "1999999, Tom Cruse, 50, Male, Tom, 10001"
我还遵循了网址: https://gist.github.com/arsperger/6f246f21279edf3cd03ba2bee19daaef和 https://www.alibabacloud.com/help/doc-detail/26357.htm ,但cat不支持Windows版本.
I also followed url: https://gist.github.com/arsperger/6f246f21279edf3cd03ba2bee19daaef and https://www.alibabacloud.com/help/doc-detail/26357.htm, but cat will not support to the windows version.
您能给我指路吗?
推荐答案
例如,当您使用提到的"Git Bash"时,您可以执行以下操作(最后一步输出命令,但也可以将它们通过管道传递给redis-cli
:
For instance when you use mentioned "Git Bash" you can do as follows (last step outputs the commands, but they may as well be piped to redis-cli
:
以上内容来自Windows的Git 2.17.1.最终的命令行是:
The above comes from Git 2.17.1 for Windows. The final command-line is:
tail -n +2 test.csv | awk -F',' '{print "SET \""$1"\" \""$0"\""}' | redis-cli
请注意以下两个假设:
- CSV中的字符串没有用双引号引起来-如果是这样,则在输出"SET"命令时必须将其转义
- CSV的第一行包含标题,并且值用逗号分隔.
这篇关于使用Windows版本的Redis-cli在Redis中加载CSV文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!