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)
...
as in HSET we should define 3 parameter i write this code. Isn’t there a better solution?
2
Answers
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
you can do this
It’s documented here
https://redis.io/commands/hmset and https://redis.io/commands/hset
but
hmset
is deprecated and you should usehset
now because it supports the same args ashmset
in node.js, if you already have the key / value in an object, you can do this