node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

Cannot pass array of objects

Open kachangch opened this issue 2 years ago • 0 comments

Description

Hi, I have encountered an issue where I try to use JSON.set for an array of objects, however, it shows a type error when it tries so set the value in the cache.

    REDIS: Setting JSON cached value of {
      key: 'TEST-KEY',
      path: '$',
      value: [ { A: 'test' } ]
    }

      at src/redis/redis.ts:177:17

  console.error
    {
      data: {
        key: 'TEST-KEY,
        value: [ [Object] ],
        expires: 5,
        path: '$'
      },
      error: 'value must be a `object` type, but the final value was: `[\n' +
        '  {\n' +
        '    "A": "\\"test\\""\n' +
        '  }\n' +
        ']`.'
    }

Is there a specific syntax that I need to follow that allows me to write an array of objects to the cache? Or is this an issue? The work around I have for now is to pass an object with a key containing the array of objects which is not ideal. For example:

TEST = {
    SOME_KEY: [{...}, {...}]
}

Node.js Version

16.19

Redis Server Version

7.0.7

Node Redis Version

4.6.10

Platform

masOS

Logs

No response

kachangch avatar Oct 19 '23 00:10 kachangch