-7

I want to store an array of objects in redis

const items = [
  {
    '122': {
      name: 'abc',
      price: '12',
    },
  },
  {
    '1225656': {
      name: 'bc',
      price: '35',
    },
  },
];
felixmosh
  • 32,615
  • 9
  • 69
  • 88
Basir Baig
  • 111
  • 1
  • 8

1 Answers1

1

if you were to use string data type, this is how you do it

// set it
await redis.set('keyname', JSON.stringify(items))

// get it back

const dataStr = await redis.get('keyname')
const data = JSON.parse(dataStr)

of course you can use other data type like hash (or storing list items) and list (item keys) all together. but if the json payload is small, I think you will be just fine using string.

Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54