Can you save nested objects in redis?
你能在redis中保存嵌套对象吗?
I'm using the node.js driver. One of my key-values is an array of objects. If I dont stringify it results in the string "[object Object]" if i stringify it I get this error:
我正在使用node.js驱动程序。我的一个键值是一个对象数组。如果我没有字符串化它会导致字符串“[object Object]”如果我将其字符串化,我会收到此错误:
{
stack: [Getter/Setter],
arguments: undefined,
type: undefined,
message: 'ERR wrong number of arguments for \'hmset\' command'
}
2 个解决方案
#1
3
stringifying json is not the right way of using redis. you should generate your own redis hashsets
字符串化json不是使用redis的正确方法。你应该生成自己的redis hashsets
user:ejder name ejder user:ejder:details:0 age 32 user:ejder:details:1 age 25 (i wish)
user:ejder name ejder user:ejder:details:0 age 32 user:ejder:details:1 age 25(i wish)
that way you can query your data redis-way. Stringifying json is nothing but saving a string and if you use large datasets it will decrease the performance very bad
这样您就可以通过redis-way查询数据。字符串化json只是保存一个字符串,如果你使用大型数据集,它会降低性能非常糟糕
#2
1
Stringifying simple object to it's JSON representations should work and it seems that you have some syntax error in your code (can you please update your question with corresponding code where you are doing the HMSET command?). If you are not ok with stringified version, then each of your object in array should have dedicated hash structure where their data would be located.
将简单对象字符串化为它的JSON表示应该有效,并且您的代码中似乎有一些语法错误(您可以使用相应的代码更新您的问题,而您正在执行HMSET命令吗?)。如果您对字符串化版本不满意,那么数组中的每个对象都应该具有专用的哈希结构,其中的数据将位于其中。
Alternatively you can try to use node.js implementation of a object-hash mapping library for redis.
或者,您可以尝试使用对象哈希映射库的node.js实现来实现redis。
#1
3
stringifying json is not the right way of using redis. you should generate your own redis hashsets
字符串化json不是使用redis的正确方法。你应该生成自己的redis hashsets
user:ejder name ejder user:ejder:details:0 age 32 user:ejder:details:1 age 25 (i wish)
user:ejder name ejder user:ejder:details:0 age 32 user:ejder:details:1 age 25(i wish)
that way you can query your data redis-way. Stringifying json is nothing but saving a string and if you use large datasets it will decrease the performance very bad
这样您就可以通过redis-way查询数据。字符串化json只是保存一个字符串,如果你使用大型数据集,它会降低性能非常糟糕
#2
1
Stringifying simple object to it's JSON representations should work and it seems that you have some syntax error in your code (can you please update your question with corresponding code where you are doing the HMSET command?). If you are not ok with stringified version, then each of your object in array should have dedicated hash structure where their data would be located.
将简单对象字符串化为它的JSON表示应该有效,并且您的代码中似乎有一些语法错误(您可以使用相应的代码更新您的问题,而您正在执行HMSET命令吗?)。如果您对字符串化版本不满意,那么数组中的每个对象都应该具有专用的哈希结构,其中的数据将位于其中。
Alternatively you can try to use node.js implementation of a object-hash mapping library for redis.
或者,您可以尝试使用对象哈希映射库的node.js实现来实现redis。