问题描述
我对Redis中的HSET有疑问.据我所知,redis是一个键值数据库.这意味着每件事物都存储为键值,例如,我们没有表.我想在redis中保存一些内容,所以我决定使用Hashmap.由于HMSET已过时,我们应该改用HSET,我应该如何在hset中存储许多属性作为值和id作为键?你知道我想保存这样的东西:
i have a question about HSET in redis. As far as i know, redis is a key-value database. that means every thing store as a key-value and we don't have table for example.i wanted to save something in redis so i decided to use Hashmap . since the HMSET is deprecated and we should use HSET instead, how should I store many attribute as a value and a id as a key in hset?you know i want to save some thing like this:
await redis.hset(`origin-${originId}`, 'title',title)
但是如果我要保存很多字段,我应该为每个字段写这一行?例如:
but if i have many fields to save i should write this line for each field?? for example :
await redis.hset(`origin-${originId}`, 'title',title)
await redis.hset(`origin-${originId}`, 'status',status)
...
就像在HSET中一样,我们应该定义3个参数,然后编写此代码.有没有更好的解决方案?
as in HSET we should define 3 parameter i write this code. Isn't there a better solution?
推荐答案
我发现我的问题出在我的Redis客户端上.我的redise版本是5,但是我的redis客户端不支持Redis 5的新功能.因此,我使用 ioredis ,并且此Redis客户端支持hmset.也有针对该问题的修复程序,但尚未发布,请参见在此处输入链接描述
i figure out that my problem was with my redis client. my redise version is 5 but my redis client doesn't support new features in Redis 5.so i use ioredis and this redis client support hmset now. also there is a fix for that issue but wasn't released yet see enter link description here
这篇关于如何使用hashmap(HSET)将Json存储在Redis中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!