0

I am trying to generate a file for mass insertion in shape:

SET Key0 Value0
SET Key1 Value1
...
SET KeyN ValueN

In my case, I have newlines in values. How to write values in this case since \n means new command. Can I use quotation mark to wrap a value with a newline character?

2
  • Yes, you can. Why don't try it instead of posting a question? If you fail, come back with the details :) Commented Mar 2, 2018 at 13:14
  • I wrap my values like this SET key "value with \n in between" but I still get ERR unknown command. It looks like that Redis still interpret newlines inside values as a start of the new command. So how can I wrap values with newlines inside that will not raise this error. Commented Mar 2, 2018 at 13:53

1 Answer 1

3

Redis doesn't care about what you store as string values. What may be getting in your way is the client/programming language that you're using.

For example, the below is the output of using the redis-cli tool that ships with Redis:

$ redis-cli
127.0.0.1:6379> SET foo "1st\n2nd"
OK
127.0.0.1:6379> GET foo
"1st\n2nd"
127.0.0.1:6379> QUIT
$ redis-cli --raw
127.0.0.1:6379> GET foo
1st
2nd
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for explaining. My problem was that I did not escape newlines when writing insertion file in Python. Newlines need to be written as a string "\n" inside value and not as a real newline.
Ah - that's why it's always good to attach the code to the question :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.