Values with embedded newline characters

35 views
Skip to first unread message

Luveh Keraph

unread,
Nov 22, 2023, 3:12:36 PM11/22/23
to redi...@googlegroups.com
While this is not strictly a Redis issue, maybe somebody in this forum can offer suggestions as to how to get around the issue that I am inquiring about.

From the Redis command line I can do things like the following:

127.0.0.1:6379> SET mykey "Line 1\nLine 2"

With  this, I have the following:

$ redis-cli GET foo
"Line 1\nLine 2"

$ redis-cli --raw GET foo
Line 1
Line 2

We now do the same thing but taking a somewhat different approach from the Linux command line:

$ redis-cli SET foo "Line 1\nLine 2"
OK

$ redis-cli GET foo
"Line 1\\nLine 2"

$ redis-cli --raw GET foo
Line 1\nLine 2

Anybody know how to prevent that extra backslash from being added?

Luveh Keraph

unread,
Nov 22, 2023, 3:25:34 PM11/22/23
to redi...@googlegroups.com
As is often the case, I found out how to do it five minutes after I posted the question below. In case this can be of use to anybody, here's the deal:

In a simple script:

#! /bin/sh

ret=$'\n'

redis-cli SET foo "1st${ret}2nd${ret}"
redis-cli APPEND foo "3rd${ret}4th"

redis-cli GET foo
redis-cli --raw GET foo

On running it we get

OK
(integer) 15
"1st\n2nd\n3rd\n4th"
1st
2nd
3rd
4th

This works for Bash, the shell that I am using.
Reply all
Reply to author
Forward
0 new messages