I am trying to insert the CSV data into Redis using the below command
Column1 | Column2 |
---|---|
long_ago/speech: | well-done speech |
long-ago/debate: | well-done debate |
long ago/work: | well-done work |
awk -F ',' 'FNR > 1 && $1 && $2 {printf("SET Topic:%s %s\n",$1,$2)}' data_topics.csv | redis-cli --pipe
The expectation is when I do
GET "Topic:long_ago/speech:"
should print
>"well-done speech"
But I am not getting any output when I tried inserting 1000 rows in CSV. So have tried with the above 3 rows in CSV and getting the below error
[admin~]$ awk -F ',' 'FNR > 1 && $1 && $2 {printf("SET Topic:%s %s\n",$1,$2)}' data_topics.csv | redis-cli --pipe
All data transferred. Waiting for the last reply...
ERR syntax error
ERR syntax error
ERR syntax error
Last reply received from the server.
errors: 3, Replies: 3
So I have tried adding double quotes in the 2nd column, now my CSV looks something like the below
Column1 | Column2 |
---|---|
long_ago/speech: | "well-done speech" |
long-ago/debate: | "well-done debate" |
long ago/work: | "well-done work" |
and this is the error I am getting now -
[admin~]$ awk -F ',' 'FNR > 1 && $1 && $2 {printf("SET Topic:%s %s\n",$1,$2)}' data_topics.csv | redis-cli --pipe
All data transferred. Waiting for the last reply...
ERR Protocol error: unbalanced quotes in request
Please help me to insert my CSV data into Redis.
CodePudding user response:
Using a CSV called data.csv
that contains this:
long_ago/speech:,well-done speech
long-ago/debate:,well-done debate
long-ago/work:,well-done work
You could use:
awk -F, '{printf("SET \"Topic:%s\" \"%s\"\n",$1,$2)}' data.csv | redis-cli --pipe
Then you could do:
redis-cli GET "Topic:long_ago/speech:"
"well-done speech"