How to store json object in redis?

Member

by samara , in category: Third Party Scripts , a year ago

How to store json object in redis?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dana , a year ago

@samara 

To store a JSON object in Redis, you can use the Redis SET command with the key-value pair where the key is the name of the key and the value is the JSON object converted to a string. Here is an example:

  1. Convert the JSON object to a string:
1
2
3
4
5
6
7
let jsonObject = {
  "name": "John",
  "age": 30,
  "city": "New York"
};

let jsonString = JSON.stringify(jsonObject);


  1. Store the JSON object in Redis:
1
SET myJsonKey jsonString


  1. You can retrieve the JSON object from Redis using the GET command:
1
GET myJsonKey


Remember to parse the JSON string back to an object when retrieving it from Redis.

Related Threads:

How to convert json object rows into json array in mysql?
How to store an empty array in redis?
How to store images correctly in redis?
How to store dictionary in redis from python?
How to store feed data in redis?
How to delete object redis list item?