Viktor K.
Viktor K.

Reputation: 2740

Redis command line SET value containing double quotes

I want to use redis command line (using redis-cli) to store json values. This is what I do

redis 127.0.0.1:6379> set test '{"a":"b"}'

This command fails with message :

Invalid argument(s)

I don't have problem with setting values that don't contain double quotes. What is the correct way to escape double quotes?

Upvotes: 35

Views: 29110

Answers (3)

Ravi Singh
Ravi Singh

Reputation: 81

We can use single quotes for storing the JSON value:

set name '{"a":"b"}'

Run get query like: get name

output : {"a":"b"}

Upvotes: 8

aGuegu
aGuegu

Reputation: 2301

later redis has fixed this problem. single quote works fine.

Upvotes: 6

Marty Aghajanyan
Marty Aghajanyan

Reputation: 13409

Add slashes to quotes

set test "{\"a\":\"b\"}"

Upvotes: 45

Related Questions