1

I went through questions like how to import a ".csv " data-file into the Redis database and decided to put a question here after lot of web searching.

I've an employee.csv file and looking to import that file using the redis-cli. I am using the Windows version 3.2.100 of Redis server.

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"

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.

What can I try next?

halfer
  • 19,824
  • 17
  • 99
  • 186
PAA
  • 1
  • 46
  • 174
  • 282
  • You could either use [Cygwin](http://www.cygwin.com) or use Windows ports of specific tools like "awk" - https://stackoverflow.com/questions/21927944/how-to-run-an-awk-commands-in-windows – Tomasz Poradowski Nov 15 '18 at 14:23
  • @ Tomasz Poradowski - I used GIT bash, but it doesn't seem to be working at all. Also cygwin seems not working. Could you please try and guide us? Many Thanks sir in advance. – PAA Nov 15 '18 at 14:54

1 Answers1

2

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:

Converting simple CSV to SET commands for Redis

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

Please note a couple of assumptions:

  • Strings in CSV are not enclosed in double quotes - if so you'd have to escape them when outputting "SET" commands
  • First line in CSV contains headers and values are separated with a comma.
Tomasz Poradowski
  • 1,251
  • 11
  • 12
  • We're getting below error. Bash will never be able to understand `redis-cli.exe` ```$ tail -n +2 test.csv | awk -F',' '{print "SET \""$1"\" \""$0"\""}' | redis-cli bash: redis-cli: command not found``` – PAA Nov 16 '18 at 12:04
  • @PAA either use full path like `/c/Program\ Files/Redis/redis-cli` or change the PATH variable via `export PATH=$PATH:/c/Program\ Files/Redis` – Tomasz Poradowski Nov 16 '18 at 12:28