In redis:

127.0.0.1:6379[1]> set hello 'a\nb'
OK
127.0.0.1:6379[1]> get hello
"a\\nb"
127.0.0.1:6379[1]> set hello1 "a\nb"
OK
127.0.0.1:6379[1]> get hello1
"a\nb"

Redis doesn't treat \ as an escape char when use single quota.

But in mongodb:

acmcoder:PRIMARY> db.test.insert({hello:'a\nb'})
WriteResult({ "nInserted" : 1 })
acmcoder:PRIMARY> db.test.find()
{ "_id" : ObjectId("5e53e8a550987ffc2e916ec4"), "hello" : "a\nb" }
acmcoder:PRIMARY> db.test.insert({hello1:"a\nb"})
WriteResult({ "nInserted" : 1 })
acmcoder:PRIMARY> db.test.find()
{ "_id" : ObjectId("5e53e8a550987ffc2e916ec4"), "hello" : "a\nb" }
{ "_id" : ObjectId("5e53e8bd50987ffc2e916ec5"), "hello1" : "a\nb" }

Mongodb always treat \ as an escape char.

I can't find any explaination about this in redis documents. I don't know whether this is a bug or not, shall we need to fix it?

Comment From: itamarhaber

Hello @lifubang

The code (sdc.c:sdssplitargs()) seems to suggest that this behavior is by design - please feel free to open an issue/PR to the docs: https://github.com/antirez/redis-doc