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?
you can do this
hset key field1 value1 field2 value2 ...
It's documented here
https://redis.io/commands/hmset and https://redis.io/commands/hset
but hmset is deprecated and you should use hset now because it supports the same args as hmset
in node.js, if you already have the key / value in an object, you can do this
await redis.hset('myhashset', { field1: value1, field2: value2 })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With