如何使用hashmap(HSET)将Json存储在Redis中 [英] how can store a Json in redis with hashmap( HSET )

查看:1055
本文介绍了如何使用hashmap(HSET)将Json存储在Redis中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对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中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆